From 0492bddf28ecfea9a5c901e78ff07918a265f6f6 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 18 Mar 2025 17:15:56 +0000 Subject: [PATCH 01/42] chore(internal): version bump (#157) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 99c7eb77..3e33c451 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ The Braintrust Java SDK is similar to the Braintrust Kotlin SDK but with minor d It is generated with [Stainless](https://www.stainless.com/). -The REST API documentation can be found on [www.braintrustdata.com](https://www.braintrustdata.com/docs/api/spec). Javadocs are also available on [javadoc.io](https://javadoc.io/doc/com.braintrustdata.api/braintrust-java/0.7.0). +The REST API documentation can be found on [www.braintrustdata.com](https://www.braintrustdata.com/docs/api/spec). Javadocs are also available on [javadoc.io](https://javadoc.io/doc/com.braintrustdata.api/braintrust-java/0.8.0). ## Installation From 45cca506a7c0c1a165c0d4e54bf1950d4256d3a2 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 19 Mar 2025 12:58:59 +0000 Subject: [PATCH 02/42] chore(internal): codegen related update (#159) --- .../api/models/AclDeleteParams.kt | 13 +- .../api/models/AclRetrieveParams.kt | 13 +- .../api/models/AiSecretDeleteParams.kt | 13 +- .../api/models/AiSecretRetrieveParams.kt | 13 +- .../api/models/AiSecretUpdateParams.kt | 13 +- .../api/models/ApiKeyDeleteParams.kt | 13 +- .../api/models/ApiKeyRetrieveParams.kt | 13 +- .../api/models/DatasetDeleteParams.kt | 13 +- .../api/models/DatasetFeedbackParams.kt | 13 +- .../api/models/DatasetFetchParams.kt | 13 +- .../api/models/DatasetFetchPostParams.kt | 13 +- .../api/models/DatasetInsertParams.kt | 13 +- .../api/models/DatasetRetrieveParams.kt | 13 +- .../api/models/DatasetSummarizeParams.kt | 13 +- .../api/models/DatasetUpdateParams.kt | 13 +- .../api/models/EnvVarDeleteParams.kt | 13 +- .../api/models/EnvVarRetrieveParams.kt | 13 +- .../api/models/EnvVarUpdateParams.kt | 13 +- .../api/models/ExperimentDeleteParams.kt | 13 +- .../api/models/ExperimentFeedbackParams.kt | 13 +- .../api/models/ExperimentFetchParams.kt | 13 +- .../api/models/ExperimentFetchPostParams.kt | 13 +- .../api/models/ExperimentInsertParams.kt | 13 +- .../api/models/ExperimentRetrieveParams.kt | 13 +- .../api/models/ExperimentSummarizeParams.kt | 13 +- .../api/models/ExperimentUpdateParams.kt | 13 +- .../api/models/FunctionDeleteParams.kt | 13 +- .../api/models/FunctionInvokeParams.kt | 13 +- .../api/models/FunctionRetrieveParams.kt | 13 +- .../api/models/FunctionUpdateParams.kt | 13 +- .../api/models/GroupDeleteParams.kt | 13 +- .../api/models/GroupRetrieveParams.kt | 13 +- .../api/models/GroupUpdateParams.kt | 13 +- .../api/models/OrganizationDeleteParams.kt | 13 +- .../api/models/OrganizationRetrieveParams.kt | 13 +- .../api/models/OrganizationUpdateParams.kt | 13 +- .../api/models/ProjectDeleteParams.kt | 13 +- .../api/models/ProjectLogFeedbackParams.kt | 13 +- .../api/models/ProjectLogFetchParams.kt | 13 +- .../api/models/ProjectLogFetchPostParams.kt | 13 +- .../api/models/ProjectLogInsertParams.kt | 13 +- .../api/models/ProjectRetrieveParams.kt | 13 +- .../api/models/ProjectScoreDeleteParams.kt | 13 +- .../api/models/ProjectScoreRetrieveParams.kt | 13 +- .../api/models/ProjectScoreUpdateParams.kt | 13 +- .../api/models/ProjectTagDeleteParams.kt | 13 +- .../api/models/ProjectTagRetrieveParams.kt | 13 +- .../api/models/ProjectTagUpdateParams.kt | 13 +- .../api/models/ProjectUpdateParams.kt | 13 +- .../api/models/PromptDeleteParams.kt | 13 +- .../api/models/PromptRetrieveParams.kt | 13 +- .../api/models/PromptUpdateParams.kt | 13 +- .../api/models/RoleDeleteParams.kt | 13 +- .../api/models/RoleRetrieveParams.kt | 13 +- .../api/models/RoleUpdateParams.kt | 13 +- .../api/models/SpanIframeDeleteParams.kt | 13 +- .../api/models/SpanIframeRetrieveParams.kt | 13 +- .../api/models/SpanIframeUpdateParams.kt | 13 +- .../api/models/UserRetrieveParams.kt | 13 +- .../api/models/ViewDeleteParams.kt | 13 +- .../api/models/ViewRetrieveParams.kt | 13 +- .../api/models/ViewUpdateParams.kt | 13 +- .../api/services/async/AclServiceAsyncImpl.kt | 4 +- .../async/AiSecretServiceAsyncImpl.kt | 6 +- .../services/async/ApiKeyServiceAsyncImpl.kt | 4 +- .../services/async/DatasetServiceAsyncImpl.kt | 16 +- .../services/async/EnvVarServiceAsyncImpl.kt | 6 +- .../async/ExperimentServiceAsyncImpl.kt | 16 +- .../async/FunctionServiceAsyncImpl.kt | 8 +- .../services/async/GroupServiceAsyncImpl.kt | 6 +- .../async/OrganizationServiceAsyncImpl.kt | 6 +- .../async/ProjectScoreServiceAsyncImpl.kt | 6 +- .../services/async/ProjectServiceAsyncImpl.kt | 6 +- .../async/ProjectTagServiceAsyncImpl.kt | 6 +- .../services/async/PromptServiceAsyncImpl.kt | 6 +- .../services/async/RoleServiceAsyncImpl.kt | 6 +- .../async/SpanIframeServiceAsyncImpl.kt | 6 +- .../services/async/UserServiceAsyncImpl.kt | 2 +- .../services/async/ViewServiceAsyncImpl.kt | 6 +- .../async/projects/LogServiceAsyncImpl.kt | 8 +- .../api/services/blocking/AclServiceImpl.kt | 4 +- .../services/blocking/AiSecretServiceImpl.kt | 6 +- .../services/blocking/ApiKeyServiceImpl.kt | 4 +- .../services/blocking/DatasetServiceImpl.kt | 16 +- .../services/blocking/EnvVarServiceImpl.kt | 6 +- .../blocking/ExperimentServiceImpl.kt | 16 +- .../services/blocking/FunctionServiceImpl.kt | 8 +- .../api/services/blocking/GroupServiceImpl.kt | 6 +- .../blocking/OrganizationServiceImpl.kt | 6 +- .../blocking/ProjectScoreServiceImpl.kt | 6 +- .../services/blocking/ProjectServiceImpl.kt | 6 +- .../blocking/ProjectTagServiceImpl.kt | 6 +- .../services/blocking/PromptServiceImpl.kt | 6 +- .../api/services/blocking/RoleServiceImpl.kt | 6 +- .../blocking/SpanIframeServiceImpl.kt | 6 +- .../api/services/blocking/UserServiceImpl.kt | 2 +- .../api/services/blocking/ViewServiceImpl.kt | 6 +- .../blocking/projects/LogServiceImpl.kt | 8 +- .../api/models/AclBatchUpdateParamsTest.kt | 49 +++--- .../api/models/AclDeleteParamsTest.kt | 9 +- .../api/models/AclRetrieveParamsTest.kt | 9 +- .../api/models/AiSecretDeleteParamsTest.kt | 9 +- .../api/models/AiSecretRetrieveParamsTest.kt | 9 +- .../api/models/AiSecretUpdateParamsTest.kt | 25 ++-- .../api/models/ApiKeyDeleteParamsTest.kt | 9 +- .../api/models/ApiKeyRetrieveParamsTest.kt | 9 +- .../api/models/DatasetDeleteParamsTest.kt | 9 +- .../api/models/DatasetEventTest.kt | 3 +- .../api/models/DatasetFeedbackParamsTest.kt | 56 ++++--- .../api/models/DatasetFetchParamsTest.kt | 21 ++- .../api/models/DatasetFetchPostParamsTest.kt | 25 ++-- .../api/models/DatasetInsertParamsTest.kt | 81 +++++----- .../api/models/DatasetRetrieveParamsTest.kt | 9 +- .../api/models/DatasetSummarizeParamsTest.kt | 25 ++-- .../api/models/DatasetUpdateParamsTest.kt | 21 ++- .../api/models/EnvVarDeleteParamsTest.kt | 9 +- .../api/models/EnvVarRetrieveParamsTest.kt | 9 +- .../api/models/EnvVarUpdateParamsTest.kt | 27 ++-- .../api/models/EvalCreateParamsTest.kt | 24 ++- .../api/models/ExperimentDeleteParamsTest.kt | 9 +- .../api/models/ExperimentEventTest.kt | 5 +- .../models/ExperimentFeedbackParamsTest.kt | 67 ++++----- .../api/models/ExperimentFetchParamsTest.kt | 25 ++-- .../models/ExperimentFetchPostParamsTest.kt | 25 ++-- .../api/models/ExperimentInsertParamsTest.kt | 139 +++++++++--------- .../models/ExperimentRetrieveParamsTest.kt | 9 +- .../models/ExperimentSummarizeParamsTest.kt | 25 ++-- .../api/models/ExperimentUpdateParamsTest.kt | 25 ++-- .../api/models/FeedbackDatasetItemTest.kt | 3 +- .../api/models/FeedbackExperimentItemTest.kt | 3 +- .../api/models/FeedbackProjectLogsItemTest.kt | 3 +- .../api/models/FunctionCreateParamsTest.kt | 3 +- .../api/models/FunctionDeleteParamsTest.kt | 9 +- .../api/models/FunctionInvokeParamsTest.kt | 44 +++--- .../api/models/FunctionReplaceParamsTest.kt | 3 +- .../api/models/FunctionRetrieveParamsTest.kt | 9 +- .../braintrustdata/api/models/FunctionTest.kt | 3 +- .../api/models/FunctionUpdateParamsTest.kt | 28 ++-- .../api/models/GroupCreateParamsTest.kt | 7 +- .../api/models/GroupDeleteParamsTest.kt | 9 +- .../api/models/GroupReplaceParamsTest.kt | 7 +- .../api/models/GroupRetrieveParamsTest.kt | 9 +- .../braintrustdata/api/models/GroupTest.kt | 5 +- .../api/models/GroupUpdateParamsTest.kt | 36 ++--- .../api/models/InsertDatasetEventTest.kt | 7 +- .../api/models/InsertExperimentEventTest.kt | 8 +- .../api/models/InsertProjectLogsEventTest.kt | 8 +- .../api/models/OnlineScoreConfigTest.kt | 3 +- .../models/OrganizationDeleteParamsTest.kt | 9 +- .../models/OrganizationRetrieveParamsTest.kt | 9 +- .../models/OrganizationUpdateParamsTest.kt | 25 ++-- .../api/models/ProjectDeleteParamsTest.kt | 9 +- .../models/ProjectLogFeedbackParamsTest.kt | 67 ++++----- .../api/models/ProjectLogFetchParamsTest.kt | 25 ++-- .../models/ProjectLogFetchPostParamsTest.kt | 25 ++-- .../api/models/ProjectLogInsertParamsTest.kt | 139 +++++++++--------- .../api/models/ProjectLogsEventTest.kt | 5 +- .../api/models/ProjectRetrieveParamsTest.kt | 9 +- .../models/ProjectScoreDeleteParamsTest.kt | 9 +- .../models/ProjectScoreRetrieveParamsTest.kt | 9 +- .../models/ProjectScoreUpdateParamsTest.kt | 25 ++-- .../api/models/ProjectSettingsTest.kt | 3 +- .../api/models/ProjectTagDeleteParamsTest.kt | 9 +- .../models/ProjectTagRetrieveParamsTest.kt | 9 +- .../api/models/ProjectTagUpdateParamsTest.kt | 25 ++-- .../api/models/ProjectUpdateParamsTest.kt | 21 ++- .../api/models/PromptCreateParamsTest.kt | 3 +- .../api/models/PromptDataTest.kt | 3 +- .../api/models/PromptDeleteParamsTest.kt | 9 +- .../api/models/PromptReplaceParamsTest.kt | 3 +- .../api/models/PromptRetrieveParamsTest.kt | 9 +- .../braintrustdata/api/models/PromptTest.kt | 3 +- .../api/models/PromptUpdateParamsTest.kt | 24 +-- .../api/models/RoleCreateParamsTest.kt | 18 +-- .../api/models/RoleDeleteParamsTest.kt | 9 +- .../api/models/RoleReplaceParamsTest.kt | 18 +-- .../api/models/RoleRetrieveParamsTest.kt | 9 +- .../com/braintrustdata/api/models/RoleTest.kt | 6 +- .../api/models/RoleUpdateParamsTest.kt | 57 ++++--- .../api/models/SpanIframeDeleteParamsTest.kt | 9 +- .../models/SpanIframeRetrieveParamsTest.kt | 9 +- .../api/models/SpanIframeUpdateParamsTest.kt | 25 ++-- .../api/models/UserRetrieveParamsTest.kt | 9 +- .../api/models/ViewDataSearchTest.kt | 10 +- .../api/models/ViewDeleteParamsTest.kt | 27 +--- .../api/models/ViewOptionsTest.kt | 3 +- .../api/models/ViewRetrieveParamsTest.kt | 31 +--- .../api/models/ViewUpdateParamsTest.kt | 29 ++-- 188 files changed, 1322 insertions(+), 1470 deletions(-) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclDeleteParams.kt index 1aaf3f66..a0eda97b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclDeleteParams.kt @@ -34,16 +34,15 @@ private constructor( internal fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> aclId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclRetrieveParams.kt index a591bf37..6050054f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclRetrieveParams.kt @@ -24,16 +24,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> aclId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretDeleteParams.kt index 2fa3533f..e0f617ff 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretDeleteParams.kt @@ -34,16 +34,15 @@ private constructor( internal fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> aiSecretId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretRetrieveParams.kt index 7ff996d2..c760c49b 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretRetrieveParams.kt @@ -24,16 +24,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> aiSecretId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt index 751a2ce2..93a5ec52 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt @@ -100,16 +100,15 @@ private constructor( @JvmSynthetic internal fun _body(): Body = body - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> aiSecretId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams @NoAutoDetect class Body diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParams.kt index cc0903b2..35683e37 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParams.kt @@ -34,16 +34,15 @@ private constructor( internal fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> apiKeyId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyRetrieveParams.kt index 1a0b9c18..c32d98c6 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyRetrieveParams.kt @@ -24,16 +24,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> apiKeyId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetDeleteParams.kt index 67c7b316..8f10efea 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetDeleteParams.kt @@ -34,16 +34,15 @@ private constructor( internal fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> datasetId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFeedbackParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFeedbackParams.kt index bb641fb0..fa07b30f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFeedbackParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFeedbackParams.kt @@ -56,16 +56,15 @@ private constructor( @JvmSynthetic internal fun _body(): Body = body - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> datasetId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams @NoAutoDetect class Body diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchParams.kt index b00ce504..ac0671bb 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchParams.kt @@ -86,6 +86,12 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams + fun _pathParam(index: Int): String = + when (index) { + 0 -> datasetId + else -> "" + } + override fun _headers(): Headers = additionalHeaders override fun _queryParams(): QueryParams = @@ -99,13 +105,6 @@ private constructor( } .build() - fun getPathParam(index: Int): String { - return when (index) { - 0 -> datasetId - else -> "" - } - } - fun toBuilder() = Builder().from(this) companion object { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt index b829eb13..96722a3c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt @@ -156,16 +156,15 @@ private constructor( @JvmSynthetic internal fun _body(): Body = body - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> datasetId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams @NoAutoDetect class Body diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetInsertParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetInsertParams.kt index 8ed1370b..0cc348dd 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetInsertParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetInsertParams.kt @@ -56,16 +56,15 @@ private constructor( @JvmSynthetic internal fun _body(): Body = body - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> datasetId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams @NoAutoDetect class Body diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetRetrieveParams.kt index ef2657ae..57c19cd2 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetRetrieveParams.kt @@ -24,16 +24,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> datasetId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetSummarizeParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetSummarizeParams.kt index d188b51b..f20aadaf 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetSummarizeParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetSummarizeParams.kt @@ -30,6 +30,12 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams + fun _pathParam(index: Int): String = + when (index) { + 0 -> datasetId + else -> "" + } + override fun _headers(): Headers = additionalHeaders override fun _queryParams(): QueryParams = @@ -40,13 +46,6 @@ private constructor( } .build() - fun getPathParam(index: Int): String { - return when (index) { - 0 -> datasetId - else -> "" - } - } - fun toBuilder() = Builder().from(this) companion object { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt index 038dc497..8f6201b2 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt @@ -91,16 +91,15 @@ private constructor( @JvmSynthetic internal fun _body(): Body = body - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> datasetId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams @NoAutoDetect class Body diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarDeleteParams.kt index 8675b2e0..ba7bb844 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarDeleteParams.kt @@ -34,16 +34,15 @@ private constructor( internal fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> envVarId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarRetrieveParams.kt index 588b7b7c..2ff67112 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarRetrieveParams.kt @@ -24,16 +24,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> envVarId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarUpdateParams.kt index 58ba35d3..a77e6e8c 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarUpdateParams.kt @@ -76,16 +76,15 @@ private constructor( @JvmSynthetic internal fun _body(): Body = body - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> envVarId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams @NoAutoDetect class Body diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentDeleteParams.kt index 78bec198..7ec99c28 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentDeleteParams.kt @@ -34,16 +34,15 @@ private constructor( internal fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> experimentId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParams.kt index 2558dfff..91ebe8bd 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParams.kt @@ -56,16 +56,15 @@ private constructor( @JvmSynthetic internal fun _body(): Body = body - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> experimentId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams @NoAutoDetect class Body diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchParams.kt index 93faaa22..cd0cb7c7 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchParams.kt @@ -86,6 +86,12 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams + fun _pathParam(index: Int): String = + when (index) { + 0 -> experimentId + else -> "" + } + override fun _headers(): Headers = additionalHeaders override fun _queryParams(): QueryParams = @@ -99,13 +105,6 @@ private constructor( } .build() - fun getPathParam(index: Int): String { - return when (index) { - 0 -> experimentId - else -> "" - } - } - fun toBuilder() = Builder().from(this) companion object { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParams.kt index 180f8e6a..02bb6928 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParams.kt @@ -156,16 +156,15 @@ private constructor( @JvmSynthetic internal fun _body(): Body = body - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> experimentId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams @NoAutoDetect class Body diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentInsertParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentInsertParams.kt index 16a00bbe..bb1f3275 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentInsertParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentInsertParams.kt @@ -56,16 +56,15 @@ private constructor( @JvmSynthetic internal fun _body(): Body = body - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> experimentId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams @NoAutoDetect class Body diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentRetrieveParams.kt index 54ba50ec..5f5e010a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentRetrieveParams.kt @@ -24,16 +24,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> experimentId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentSummarizeParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentSummarizeParams.kt index 10cf6fc7..bd6b68fb 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentSummarizeParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentSummarizeParams.kt @@ -41,6 +41,12 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams + fun _pathParam(index: Int): String = + when (index) { + 0 -> experimentId + else -> "" + } + override fun _headers(): Headers = additionalHeaders override fun _queryParams(): QueryParams = @@ -52,13 +58,6 @@ private constructor( } .build() - fun getPathParam(index: Int): String { - return when (index) { - 0 -> experimentId - else -> "" - } - } - fun toBuilder() = Builder().from(this) companion object { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt index 74a29345..dd47e1cb 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt @@ -168,16 +168,15 @@ private constructor( @JvmSynthetic internal fun _body(): Body = body - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> experimentId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams @NoAutoDetect class Body diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionDeleteParams.kt index 28d9eacc..d9fe23d7 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionDeleteParams.kt @@ -34,16 +34,15 @@ private constructor( internal fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> functionId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt index 407d29b9..f6a0e50d 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt @@ -151,16 +151,15 @@ private constructor( @JvmSynthetic internal fun _body(): Body = body - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> functionId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams /** The request to invoke a function */ @NoAutoDetect diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionRetrieveParams.kt index e76a50f4..cf034800 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionRetrieveParams.kt @@ -24,16 +24,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> functionId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt index be7afe1f..18729399 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt @@ -132,16 +132,15 @@ private constructor( @JvmSynthetic internal fun _body(): Body = body - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> functionId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams @NoAutoDetect class Body diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupDeleteParams.kt index 07473a4f..792f925d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupDeleteParams.kt @@ -34,16 +34,15 @@ private constructor( internal fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> groupId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupRetrieveParams.kt index 1105cf21..1e47d093 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupRetrieveParams.kt @@ -24,16 +24,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> groupId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupUpdateParams.kt index 8009fc68..f75704bb 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupUpdateParams.kt @@ -139,16 +139,15 @@ private constructor( @JvmSynthetic internal fun _body(): Body = body - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> groupId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams @NoAutoDetect class Body diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationDeleteParams.kt index a6d936fa..e543a1d3 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationDeleteParams.kt @@ -34,16 +34,15 @@ private constructor( internal fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> organizationId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationRetrieveParams.kt index 86b3cebc..e5c0ccc3 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationRetrieveParams.kt @@ -24,16 +24,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> organizationId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationUpdateParams.kt index 36741dd2..3dae5442 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationUpdateParams.kt @@ -113,16 +113,15 @@ private constructor( @JvmSynthetic internal fun _body(): Body = body - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> organizationId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams @NoAutoDetect class Body diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectDeleteParams.kt index d5ac8442..d537bce8 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectDeleteParams.kt @@ -34,16 +34,15 @@ private constructor( internal fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> projectId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParams.kt index 13ea4533..13ff8992 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParams.kt @@ -56,16 +56,15 @@ private constructor( @JvmSynthetic internal fun _body(): Body = body - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> projectId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams @NoAutoDetect class Body diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchParams.kt index a3629afc..faca3c10 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchParams.kt @@ -86,6 +86,12 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams + fun _pathParam(index: Int): String = + when (index) { + 0 -> projectId + else -> "" + } + override fun _headers(): Headers = additionalHeaders override fun _queryParams(): QueryParams = @@ -99,13 +105,6 @@ private constructor( } .build() - fun getPathParam(index: Int): String { - return when (index) { - 0 -> projectId - else -> "" - } - } - fun toBuilder() = Builder().from(this) companion object { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParams.kt index 6b1ffba5..141ca6d9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParams.kt @@ -156,16 +156,15 @@ private constructor( @JvmSynthetic internal fun _body(): Body = body - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> projectId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams @NoAutoDetect class Body diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogInsertParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogInsertParams.kt index 629a3f65..e28846e1 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogInsertParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogInsertParams.kt @@ -56,16 +56,15 @@ private constructor( @JvmSynthetic internal fun _body(): Body = body - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> projectId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams @NoAutoDetect class Body diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectRetrieveParams.kt index 36e479aa..0e14857a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectRetrieveParams.kt @@ -24,16 +24,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> projectId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreDeleteParams.kt index 8e26501a..03afc845 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreDeleteParams.kt @@ -34,16 +34,15 @@ private constructor( internal fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> projectScoreId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreRetrieveParams.kt index e2694fa2..c6b4c52b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreRetrieveParams.kt @@ -24,16 +24,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> projectScoreId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt index f008ac19..27358edf 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt @@ -129,16 +129,15 @@ private constructor( @JvmSynthetic internal fun _body(): Body = body - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> projectScoreId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams /** A project score is a user-configured score, which can be manually-labeled through the UI */ @NoAutoDetect diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagDeleteParams.kt index 9e495e9a..72050f9c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagDeleteParams.kt @@ -34,16 +34,15 @@ private constructor( internal fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> projectTagId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagRetrieveParams.kt index 36ea7037..286a939e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagRetrieveParams.kt @@ -24,16 +24,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> projectTagId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParams.kt index 6a457c6e..c9570330 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParams.kt @@ -91,16 +91,15 @@ private constructor( @JvmSynthetic internal fun _body(): Body = body - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> projectTagId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams @NoAutoDetect class Body diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectUpdateParams.kt index 3c6ecfc1..19fd07cc 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectUpdateParams.kt @@ -77,16 +77,15 @@ private constructor( @JvmSynthetic internal fun _body(): Body = body - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> projectId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams @NoAutoDetect class Body diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptDeleteParams.kt index 548ac609..5815825a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptDeleteParams.kt @@ -34,16 +34,15 @@ private constructor( internal fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> promptId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptRetrieveParams.kt index bd674855..382c2b86 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptRetrieveParams.kt @@ -24,16 +24,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> promptId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt index 2e6f019a..8a98d6da 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt @@ -122,16 +122,15 @@ private constructor( @JvmSynthetic internal fun _body(): Body = body - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> promptId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams @NoAutoDetect class Body diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleDeleteParams.kt index 9136f6ee..c5b59886 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleDeleteParams.kt @@ -34,16 +34,15 @@ private constructor( internal fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> roleId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleRetrieveParams.kt index 1afba4b5..e825713b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleRetrieveParams.kt @@ -24,16 +24,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> roleId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleUpdateParams.kt index da629d22..fee941e4 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleUpdateParams.kt @@ -142,16 +142,15 @@ private constructor( @JvmSynthetic internal fun _body(): Body = body - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> roleId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams @NoAutoDetect class Body diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeDeleteParams.kt index da0b2c4a..87082280 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeDeleteParams.kt @@ -34,16 +34,15 @@ private constructor( internal fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> spanIframeId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeRetrieveParams.kt index 003e528f..17eb5190 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeRetrieveParams.kt @@ -24,16 +24,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> spanIframeId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParams.kt index d5fa952c..2db7b7cc 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParams.kt @@ -107,16 +107,15 @@ private constructor( @JvmSynthetic internal fun _body(): Body = body - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> spanIframeId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams @NoAutoDetect class Body diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserRetrieveParams.kt index 4d668314..2f44ce84 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserRetrieveParams.kt @@ -24,16 +24,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> userId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDeleteParams.kt index 75878782..78d16f80 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDeleteParams.kt @@ -70,16 +70,15 @@ private constructor( @JvmSynthetic internal fun _body(): Body = body - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> viewId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams @NoAutoDetect class Body diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewRetrieveParams.kt index 0e6067a2..6cb34a1e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewRetrieveParams.kt @@ -32,6 +32,12 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams + fun _pathParam(index: Int): String = + when (index) { + 0 -> viewId + else -> "" + } + override fun _headers(): Headers = additionalHeaders override fun _queryParams(): QueryParams = @@ -43,13 +49,6 @@ private constructor( } .build() - fun getPathParam(index: Int): String { - return when (index) { - 0 -> viewId - else -> "" - } - } - fun toBuilder() = Builder().from(this) companion object { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewUpdateParams.kt index 1d810b26..91b468bf 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewUpdateParams.kt @@ -152,16 +152,15 @@ private constructor( @JvmSynthetic internal fun _body(): Body = body - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - fun getPathParam(index: Int): String { - return when (index) { + fun _pathParam(index: Int): String = + when (index) { 0 -> viewId else -> "" } - } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams @NoAutoDetect class Body diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AclServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AclServiceAsyncImpl.kt index ab68729d..cbd003e7 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AclServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AclServiceAsyncImpl.kt @@ -122,7 +122,7 @@ class AclServiceAsyncImpl internal constructor(private val clientOptions: Client val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "acl", params.getPathParam(0)) + .addPathSegments("v1", "acl", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -184,7 +184,7 @@ class AclServiceAsyncImpl internal constructor(private val clientOptions: Client val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "acl", params.getPathParam(0)) + .addPathSegments("v1", "acl", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepareAsync(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsyncImpl.kt index fbe03e82..f1d13c8b 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsyncImpl.kt @@ -129,7 +129,7 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "ai_secret", params.getPathParam(0)) + .addPathSegments("v1", "ai_secret", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -158,7 +158,7 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "ai_secret", params.getPathParam(0)) + .addPathSegments("v1", "ai_secret", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepareAsync(clientOptions, params) @@ -225,7 +225,7 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "ai_secret", params.getPathParam(0)) + .addPathSegments("v1", "ai_secret", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepareAsync(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsyncImpl.kt index ca00a3e4..1de80f7e 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsyncImpl.kt @@ -106,7 +106,7 @@ class ApiKeyServiceAsyncImpl internal constructor(private val clientOptions: Cli val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "api_key", params.getPathParam(0)) + .addPathSegments("v1", "api_key", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -172,7 +172,7 @@ class ApiKeyServiceAsyncImpl internal constructor(private val clientOptions: Cli val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "api_key", params.getPathParam(0)) + .addPathSegments("v1", "api_key", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepareAsync(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsyncImpl.kt index 7a5002f9..90c60136 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsyncImpl.kt @@ -157,7 +157,7 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "dataset", params.getPathParam(0)) + .addPathSegments("v1", "dataset", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -186,7 +186,7 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "dataset", params.getPathParam(0)) + .addPathSegments("v1", "dataset", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepareAsync(clientOptions, params) @@ -253,7 +253,7 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "dataset", params.getPathParam(0)) + .addPathSegments("v1", "dataset", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepareAsync(clientOptions, params) @@ -284,7 +284,7 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl val request = HttpRequest.builder() .method(HttpMethod.POST) - .addPathSegments("v1", "dataset", params.getPathParam(0), "feedback") + .addPathSegments("v1", "dataset", params._pathParam(0), "feedback") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepareAsync(clientOptions, params) @@ -315,7 +315,7 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "dataset", params.getPathParam(0), "fetch") + .addPathSegments("v1", "dataset", params._pathParam(0), "fetch") .build() .prepareAsync(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -345,7 +345,7 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl val request = HttpRequest.builder() .method(HttpMethod.POST) - .addPathSegments("v1", "dataset", params.getPathParam(0), "fetch") + .addPathSegments("v1", "dataset", params._pathParam(0), "fetch") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepareAsync(clientOptions, params) @@ -376,7 +376,7 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl val request = HttpRequest.builder() .method(HttpMethod.POST) - .addPathSegments("v1", "dataset", params.getPathParam(0), "insert") + .addPathSegments("v1", "dataset", params._pathParam(0), "insert") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepareAsync(clientOptions, params) @@ -407,7 +407,7 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "dataset", params.getPathParam(0), "summarize") + .addPathSegments("v1", "dataset", params._pathParam(0), "summarize") .build() .prepareAsync(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EnvVarServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EnvVarServiceAsyncImpl.kt index c4ed7f35..6a418414 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EnvVarServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EnvVarServiceAsyncImpl.kt @@ -121,7 +121,7 @@ class EnvVarServiceAsyncImpl internal constructor(private val clientOptions: Cli val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "env_var", params.getPathParam(0)) + .addPathSegments("v1", "env_var", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -150,7 +150,7 @@ class EnvVarServiceAsyncImpl internal constructor(private val clientOptions: Cli val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "env_var", params.getPathParam(0)) + .addPathSegments("v1", "env_var", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepareAsync(clientOptions, params) @@ -209,7 +209,7 @@ class EnvVarServiceAsyncImpl internal constructor(private val clientOptions: Cli val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "env_var", params.getPathParam(0)) + .addPathSegments("v1", "env_var", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepareAsync(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsyncImpl.kt index 432baacd..6e013716 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsyncImpl.kt @@ -157,7 +157,7 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "experiment", params.getPathParam(0)) + .addPathSegments("v1", "experiment", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -186,7 +186,7 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "experiment", params.getPathParam(0)) + .addPathSegments("v1", "experiment", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepareAsync(clientOptions, params) @@ -253,7 +253,7 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "experiment", params.getPathParam(0)) + .addPathSegments("v1", "experiment", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepareAsync(clientOptions, params) @@ -284,7 +284,7 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: val request = HttpRequest.builder() .method(HttpMethod.POST) - .addPathSegments("v1", "experiment", params.getPathParam(0), "feedback") + .addPathSegments("v1", "experiment", params._pathParam(0), "feedback") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepareAsync(clientOptions, params) @@ -315,7 +315,7 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "experiment", params.getPathParam(0), "fetch") + .addPathSegments("v1", "experiment", params._pathParam(0), "fetch") .build() .prepareAsync(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -345,7 +345,7 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: val request = HttpRequest.builder() .method(HttpMethod.POST) - .addPathSegments("v1", "experiment", params.getPathParam(0), "fetch") + .addPathSegments("v1", "experiment", params._pathParam(0), "fetch") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepareAsync(clientOptions, params) @@ -376,7 +376,7 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: val request = HttpRequest.builder() .method(HttpMethod.POST) - .addPathSegments("v1", "experiment", params.getPathParam(0), "insert") + .addPathSegments("v1", "experiment", params._pathParam(0), "insert") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepareAsync(clientOptions, params) @@ -407,7 +407,7 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "experiment", params.getPathParam(0), "summarize") + .addPathSegments("v1", "experiment", params._pathParam(0), "summarize") .build() .prepareAsync(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsyncImpl.kt index 27377950..aac9e675 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsyncImpl.kt @@ -131,7 +131,7 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "function", params.getPathParam(0)) + .addPathSegments("v1", "function", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -160,7 +160,7 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "function", params.getPathParam(0)) + .addPathSegments("v1", "function", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepareAsync(clientOptions, params) @@ -227,7 +227,7 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "function", params.getPathParam(0)) + .addPathSegments("v1", "function", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepareAsync(clientOptions, params) @@ -258,7 +258,7 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C val request = HttpRequest.builder() .method(HttpMethod.POST) - .addPathSegments("v1", "function", params.getPathParam(0), "invoke") + .addPathSegments("v1", "function", params._pathParam(0), "invoke") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepareAsync(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/GroupServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/GroupServiceAsyncImpl.kt index db541802..0c1a8fb9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/GroupServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/GroupServiceAsyncImpl.kt @@ -121,7 +121,7 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "group", params.getPathParam(0)) + .addPathSegments("v1", "group", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -150,7 +150,7 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "group", params.getPathParam(0)) + .addPathSegments("v1", "group", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepareAsync(clientOptions, params) @@ -217,7 +217,7 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "group", params.getPathParam(0)) + .addPathSegments("v1", "group", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepareAsync(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsyncImpl.kt index 08667293..f85808a0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsyncImpl.kt @@ -87,7 +87,7 @@ class OrganizationServiceAsyncImpl internal constructor(private val clientOption val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "organization", params.getPathParam(0)) + .addPathSegments("v1", "organization", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -116,7 +116,7 @@ class OrganizationServiceAsyncImpl internal constructor(private val clientOption val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "organization", params.getPathParam(0)) + .addPathSegments("v1", "organization", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepareAsync(clientOptions, params) @@ -183,7 +183,7 @@ class OrganizationServiceAsyncImpl internal constructor(private val clientOption val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "organization", params.getPathParam(0)) + .addPathSegments("v1", "organization", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepareAsync(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsyncImpl.kt index cde96d23..f54aaad8 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsyncImpl.kt @@ -121,7 +121,7 @@ class ProjectScoreServiceAsyncImpl internal constructor(private val clientOption val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "project_score", params.getPathParam(0)) + .addPathSegments("v1", "project_score", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -150,7 +150,7 @@ class ProjectScoreServiceAsyncImpl internal constructor(private val clientOption val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "project_score", params.getPathParam(0)) + .addPathSegments("v1", "project_score", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepareAsync(clientOptions, params) @@ -217,7 +217,7 @@ class ProjectScoreServiceAsyncImpl internal constructor(private val clientOption val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "project_score", params.getPathParam(0)) + .addPathSegments("v1", "project_score", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepareAsync(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsyncImpl.kt index dba161a5..ca777a86 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsyncImpl.kt @@ -125,7 +125,7 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "project", params.getPathParam(0)) + .addPathSegments("v1", "project", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -154,7 +154,7 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "project", params.getPathParam(0)) + .addPathSegments("v1", "project", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepareAsync(clientOptions, params) @@ -221,7 +221,7 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "project", params.getPathParam(0)) + .addPathSegments("v1", "project", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepareAsync(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsyncImpl.kt index d12a821a..ed1784d6 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsyncImpl.kt @@ -121,7 +121,7 @@ class ProjectTagServiceAsyncImpl internal constructor(private val clientOptions: val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "project_tag", params.getPathParam(0)) + .addPathSegments("v1", "project_tag", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -150,7 +150,7 @@ class ProjectTagServiceAsyncImpl internal constructor(private val clientOptions: val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "project_tag", params.getPathParam(0)) + .addPathSegments("v1", "project_tag", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepareAsync(clientOptions, params) @@ -217,7 +217,7 @@ class ProjectTagServiceAsyncImpl internal constructor(private val clientOptions: val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "project_tag", params.getPathParam(0)) + .addPathSegments("v1", "project_tag", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepareAsync(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/PromptServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/PromptServiceAsyncImpl.kt index 7772aa68..9ab510a4 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/PromptServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/PromptServiceAsyncImpl.kt @@ -121,7 +121,7 @@ class PromptServiceAsyncImpl internal constructor(private val clientOptions: Cli val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "prompt", params.getPathParam(0)) + .addPathSegments("v1", "prompt", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -150,7 +150,7 @@ class PromptServiceAsyncImpl internal constructor(private val clientOptions: Cli val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "prompt", params.getPathParam(0)) + .addPathSegments("v1", "prompt", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepareAsync(clientOptions, params) @@ -217,7 +217,7 @@ class PromptServiceAsyncImpl internal constructor(private val clientOptions: Cli val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "prompt", params.getPathParam(0)) + .addPathSegments("v1", "prompt", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepareAsync(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/RoleServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/RoleServiceAsyncImpl.kt index f4809686..17f4fe44 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/RoleServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/RoleServiceAsyncImpl.kt @@ -121,7 +121,7 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "role", params.getPathParam(0)) + .addPathSegments("v1", "role", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -150,7 +150,7 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "role", params.getPathParam(0)) + .addPathSegments("v1", "role", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepareAsync(clientOptions, params) @@ -217,7 +217,7 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "role", params.getPathParam(0)) + .addPathSegments("v1", "role", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepareAsync(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsyncImpl.kt index 6dd3a6b3..4d4bbb6f 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsyncImpl.kt @@ -121,7 +121,7 @@ class SpanIframeServiceAsyncImpl internal constructor(private val clientOptions: val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "span_iframe", params.getPathParam(0)) + .addPathSegments("v1", "span_iframe", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -150,7 +150,7 @@ class SpanIframeServiceAsyncImpl internal constructor(private val clientOptions: val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "span_iframe", params.getPathParam(0)) + .addPathSegments("v1", "span_iframe", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepareAsync(clientOptions, params) @@ -217,7 +217,7 @@ class SpanIframeServiceAsyncImpl internal constructor(private val clientOptions: val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "span_iframe", params.getPathParam(0)) + .addPathSegments("v1", "span_iframe", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepareAsync(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/UserServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/UserServiceAsyncImpl.kt index 54c73c41..3537d101 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/UserServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/UserServiceAsyncImpl.kt @@ -58,7 +58,7 @@ class UserServiceAsyncImpl internal constructor(private val clientOptions: Clien val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "user", params.getPathParam(0)) + .addPathSegments("v1", "user", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ViewServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ViewServiceAsyncImpl.kt index 644bd149..9af1e4de 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ViewServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ViewServiceAsyncImpl.kt @@ -121,7 +121,7 @@ class ViewServiceAsyncImpl internal constructor(private val clientOptions: Clien val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "view", params.getPathParam(0)) + .addPathSegments("v1", "view", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -150,7 +150,7 @@ class ViewServiceAsyncImpl internal constructor(private val clientOptions: Clien val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "view", params.getPathParam(0)) + .addPathSegments("v1", "view", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepareAsync(clientOptions, params) @@ -217,7 +217,7 @@ class ViewServiceAsyncImpl internal constructor(private val clientOptions: Clien val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "view", params.getPathParam(0)) + .addPathSegments("v1", "view", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepareAsync(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/projects/LogServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/projects/LogServiceAsyncImpl.kt index 7c47266f..61d2e6a4 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/projects/LogServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/projects/LogServiceAsyncImpl.kt @@ -77,7 +77,7 @@ class LogServiceAsyncImpl internal constructor(private val clientOptions: Client val request = HttpRequest.builder() .method(HttpMethod.POST) - .addPathSegments("v1", "project_logs", params.getPathParam(0), "feedback") + .addPathSegments("v1", "project_logs", params._pathParam(0), "feedback") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepareAsync(clientOptions, params) @@ -108,7 +108,7 @@ class LogServiceAsyncImpl internal constructor(private val clientOptions: Client val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "project_logs", params.getPathParam(0), "fetch") + .addPathSegments("v1", "project_logs", params._pathParam(0), "fetch") .build() .prepareAsync(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -138,7 +138,7 @@ class LogServiceAsyncImpl internal constructor(private val clientOptions: Client val request = HttpRequest.builder() .method(HttpMethod.POST) - .addPathSegments("v1", "project_logs", params.getPathParam(0), "fetch") + .addPathSegments("v1", "project_logs", params._pathParam(0), "fetch") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepareAsync(clientOptions, params) @@ -169,7 +169,7 @@ class LogServiceAsyncImpl internal constructor(private val clientOptions: Client val request = HttpRequest.builder() .method(HttpMethod.POST) - .addPathSegments("v1", "project_logs", params.getPathParam(0), "insert") + .addPathSegments("v1", "project_logs", params._pathParam(0), "insert") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepareAsync(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AclServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AclServiceImpl.kt index b6a1b9e0..2d0f7e46 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AclServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AclServiceImpl.kt @@ -105,7 +105,7 @@ class AclServiceImpl internal constructor(private val clientOptions: ClientOptio val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "acl", params.getPathParam(0)) + .addPathSegments("v1", "acl", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -159,7 +159,7 @@ class AclServiceImpl internal constructor(private val clientOptions: ClientOptio val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "acl", params.getPathParam(0)) + .addPathSegments("v1", "acl", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AiSecretServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AiSecretServiceImpl.kt index 8824fdce..9f45ea20 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AiSecretServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AiSecretServiceImpl.kt @@ -113,7 +113,7 @@ class AiSecretServiceImpl internal constructor(private val clientOptions: Client val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "ai_secret", params.getPathParam(0)) + .addPathSegments("v1", "ai_secret", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -139,7 +139,7 @@ class AiSecretServiceImpl internal constructor(private val clientOptions: Client val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "ai_secret", params.getPathParam(0)) + .addPathSegments("v1", "ai_secret", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) @@ -194,7 +194,7 @@ class AiSecretServiceImpl internal constructor(private val clientOptions: Client val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "ai_secret", params.getPathParam(0)) + .addPathSegments("v1", "ai_secret", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ApiKeyServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ApiKeyServiceImpl.kt index cba100a5..9046ebc9 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ApiKeyServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ApiKeyServiceImpl.kt @@ -93,7 +93,7 @@ class ApiKeyServiceImpl internal constructor(private val clientOptions: ClientOp val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "api_key", params.getPathParam(0)) + .addPathSegments("v1", "api_key", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -147,7 +147,7 @@ class ApiKeyServiceImpl internal constructor(private val clientOptions: ClientOp val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "api_key", params.getPathParam(0)) + .addPathSegments("v1", "api_key", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/DatasetServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/DatasetServiceImpl.kt index 033ed993..f0ff8a15 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/DatasetServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/DatasetServiceImpl.kt @@ -138,7 +138,7 @@ class DatasetServiceImpl internal constructor(private val clientOptions: ClientO val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "dataset", params.getPathParam(0)) + .addPathSegments("v1", "dataset", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -164,7 +164,7 @@ class DatasetServiceImpl internal constructor(private val clientOptions: ClientO val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "dataset", params.getPathParam(0)) + .addPathSegments("v1", "dataset", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) @@ -219,7 +219,7 @@ class DatasetServiceImpl internal constructor(private val clientOptions: ClientO val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "dataset", params.getPathParam(0)) + .addPathSegments("v1", "dataset", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) @@ -247,7 +247,7 @@ class DatasetServiceImpl internal constructor(private val clientOptions: ClientO val request = HttpRequest.builder() .method(HttpMethod.POST) - .addPathSegments("v1", "dataset", params.getPathParam(0), "feedback") + .addPathSegments("v1", "dataset", params._pathParam(0), "feedback") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) @@ -275,7 +275,7 @@ class DatasetServiceImpl internal constructor(private val clientOptions: ClientO val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "dataset", params.getPathParam(0), "fetch") + .addPathSegments("v1", "dataset", params._pathParam(0), "fetch") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -302,7 +302,7 @@ class DatasetServiceImpl internal constructor(private val clientOptions: ClientO val request = HttpRequest.builder() .method(HttpMethod.POST) - .addPathSegments("v1", "dataset", params.getPathParam(0), "fetch") + .addPathSegments("v1", "dataset", params._pathParam(0), "fetch") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) @@ -330,7 +330,7 @@ class DatasetServiceImpl internal constructor(private val clientOptions: ClientO val request = HttpRequest.builder() .method(HttpMethod.POST) - .addPathSegments("v1", "dataset", params.getPathParam(0), "insert") + .addPathSegments("v1", "dataset", params._pathParam(0), "insert") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) @@ -358,7 +358,7 @@ class DatasetServiceImpl internal constructor(private val clientOptions: ClientO val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "dataset", params.getPathParam(0), "summarize") + .addPathSegments("v1", "dataset", params._pathParam(0), "summarize") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EnvVarServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EnvVarServiceImpl.kt index aa611b8f..a8a07079 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EnvVarServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EnvVarServiceImpl.kt @@ -102,7 +102,7 @@ class EnvVarServiceImpl internal constructor(private val clientOptions: ClientOp val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "env_var", params.getPathParam(0)) + .addPathSegments("v1", "env_var", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -128,7 +128,7 @@ class EnvVarServiceImpl internal constructor(private val clientOptions: ClientOp val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "env_var", params.getPathParam(0)) + .addPathSegments("v1", "env_var", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) @@ -181,7 +181,7 @@ class EnvVarServiceImpl internal constructor(private val clientOptions: ClientOp val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "env_var", params.getPathParam(0)) + .addPathSegments("v1", "env_var", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ExperimentServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ExperimentServiceImpl.kt index 7ec0526e..a07314c5 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ExperimentServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ExperimentServiceImpl.kt @@ -153,7 +153,7 @@ class ExperimentServiceImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "experiment", params.getPathParam(0)) + .addPathSegments("v1", "experiment", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -179,7 +179,7 @@ class ExperimentServiceImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "experiment", params.getPathParam(0)) + .addPathSegments("v1", "experiment", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) @@ -234,7 +234,7 @@ class ExperimentServiceImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "experiment", params.getPathParam(0)) + .addPathSegments("v1", "experiment", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) @@ -262,7 +262,7 @@ class ExperimentServiceImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.POST) - .addPathSegments("v1", "experiment", params.getPathParam(0), "feedback") + .addPathSegments("v1", "experiment", params._pathParam(0), "feedback") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) @@ -290,7 +290,7 @@ class ExperimentServiceImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "experiment", params.getPathParam(0), "fetch") + .addPathSegments("v1", "experiment", params._pathParam(0), "fetch") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -317,7 +317,7 @@ class ExperimentServiceImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.POST) - .addPathSegments("v1", "experiment", params.getPathParam(0), "fetch") + .addPathSegments("v1", "experiment", params._pathParam(0), "fetch") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) @@ -345,7 +345,7 @@ class ExperimentServiceImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.POST) - .addPathSegments("v1", "experiment", params.getPathParam(0), "insert") + .addPathSegments("v1", "experiment", params._pathParam(0), "insert") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) @@ -373,7 +373,7 @@ class ExperimentServiceImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "experiment", params.getPathParam(0), "summarize") + .addPathSegments("v1", "experiment", params._pathParam(0), "summarize") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceImpl.kt index cf7eb4ad..e7409dd2 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceImpl.kt @@ -115,7 +115,7 @@ class FunctionServiceImpl internal constructor(private val clientOptions: Client val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "function", params.getPathParam(0)) + .addPathSegments("v1", "function", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -141,7 +141,7 @@ class FunctionServiceImpl internal constructor(private val clientOptions: Client val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "function", params.getPathParam(0)) + .addPathSegments("v1", "function", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) @@ -196,7 +196,7 @@ class FunctionServiceImpl internal constructor(private val clientOptions: Client val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "function", params.getPathParam(0)) + .addPathSegments("v1", "function", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) @@ -224,7 +224,7 @@ class FunctionServiceImpl internal constructor(private val clientOptions: Client val request = HttpRequest.builder() .method(HttpMethod.POST) - .addPathSegments("v1", "function", params.getPathParam(0), "invoke") + .addPathSegments("v1", "function", params._pathParam(0), "invoke") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/GroupServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/GroupServiceImpl.kt index 84a146af..24e56e0f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/GroupServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/GroupServiceImpl.kt @@ -99,7 +99,7 @@ class GroupServiceImpl internal constructor(private val clientOptions: ClientOpt val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "group", params.getPathParam(0)) + .addPathSegments("v1", "group", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -125,7 +125,7 @@ class GroupServiceImpl internal constructor(private val clientOptions: ClientOpt val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "group", params.getPathParam(0)) + .addPathSegments("v1", "group", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) @@ -180,7 +180,7 @@ class GroupServiceImpl internal constructor(private val clientOptions: ClientOpt val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "group", params.getPathParam(0)) + .addPathSegments("v1", "group", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/OrganizationServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/OrganizationServiceImpl.kt index b6af330b..8171e93b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/OrganizationServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/OrganizationServiceImpl.kt @@ -86,7 +86,7 @@ class OrganizationServiceImpl internal constructor(private val clientOptions: Cl val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "organization", params.getPathParam(0)) + .addPathSegments("v1", "organization", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -112,7 +112,7 @@ class OrganizationServiceImpl internal constructor(private val clientOptions: Cl val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "organization", params.getPathParam(0)) + .addPathSegments("v1", "organization", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) @@ -169,7 +169,7 @@ class OrganizationServiceImpl internal constructor(private val clientOptions: Cl val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "organization", params.getPathParam(0)) + .addPathSegments("v1", "organization", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreServiceImpl.kt index ec7b0393..43ad2558 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreServiceImpl.kt @@ -117,7 +117,7 @@ class ProjectScoreServiceImpl internal constructor(private val clientOptions: Cl val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "project_score", params.getPathParam(0)) + .addPathSegments("v1", "project_score", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -143,7 +143,7 @@ class ProjectScoreServiceImpl internal constructor(private val clientOptions: Cl val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "project_score", params.getPathParam(0)) + .addPathSegments("v1", "project_score", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) @@ -200,7 +200,7 @@ class ProjectScoreServiceImpl internal constructor(private val clientOptions: Cl val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "project_score", params.getPathParam(0)) + .addPathSegments("v1", "project_score", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectServiceImpl.kt index 502035c3..47d5b824 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectServiceImpl.kt @@ -106,7 +106,7 @@ class ProjectServiceImpl internal constructor(private val clientOptions: ClientO val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "project", params.getPathParam(0)) + .addPathSegments("v1", "project", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -132,7 +132,7 @@ class ProjectServiceImpl internal constructor(private val clientOptions: ClientO val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "project", params.getPathParam(0)) + .addPathSegments("v1", "project", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) @@ -187,7 +187,7 @@ class ProjectServiceImpl internal constructor(private val clientOptions: ClientO val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "project", params.getPathParam(0)) + .addPathSegments("v1", "project", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectTagServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectTagServiceImpl.kt index 79f8d590..73b857af 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectTagServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectTagServiceImpl.kt @@ -117,7 +117,7 @@ class ProjectTagServiceImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "project_tag", params.getPathParam(0)) + .addPathSegments("v1", "project_tag", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -143,7 +143,7 @@ class ProjectTagServiceImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "project_tag", params.getPathParam(0)) + .addPathSegments("v1", "project_tag", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) @@ -198,7 +198,7 @@ class ProjectTagServiceImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "project_tag", params.getPathParam(0)) + .addPathSegments("v1", "project_tag", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/PromptServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/PromptServiceImpl.kt index 7736249d..8ceca7ba 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/PromptServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/PromptServiceImpl.kt @@ -99,7 +99,7 @@ class PromptServiceImpl internal constructor(private val clientOptions: ClientOp val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "prompt", params.getPathParam(0)) + .addPathSegments("v1", "prompt", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -125,7 +125,7 @@ class PromptServiceImpl internal constructor(private val clientOptions: ClientOp val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "prompt", params.getPathParam(0)) + .addPathSegments("v1", "prompt", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) @@ -180,7 +180,7 @@ class PromptServiceImpl internal constructor(private val clientOptions: ClientOp val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "prompt", params.getPathParam(0)) + .addPathSegments("v1", "prompt", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/RoleServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/RoleServiceImpl.kt index 8c0a69cb..4c9f75ec 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/RoleServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/RoleServiceImpl.kt @@ -98,7 +98,7 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "role", params.getPathParam(0)) + .addPathSegments("v1", "role", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -124,7 +124,7 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "role", params.getPathParam(0)) + .addPathSegments("v1", "role", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) @@ -179,7 +179,7 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "role", params.getPathParam(0)) + .addPathSegments("v1", "role", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/SpanIframeServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/SpanIframeServiceImpl.kt index 33029900..ac7a0da5 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/SpanIframeServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/SpanIframeServiceImpl.kt @@ -117,7 +117,7 @@ class SpanIframeServiceImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "span_iframe", params.getPathParam(0)) + .addPathSegments("v1", "span_iframe", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -143,7 +143,7 @@ class SpanIframeServiceImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "span_iframe", params.getPathParam(0)) + .addPathSegments("v1", "span_iframe", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) @@ -198,7 +198,7 @@ class SpanIframeServiceImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "span_iframe", params.getPathParam(0)) + .addPathSegments("v1", "span_iframe", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/UserServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/UserServiceImpl.kt index 08e5047d..6ce8ea6d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/UserServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/UserServiceImpl.kt @@ -50,7 +50,7 @@ class UserServiceImpl internal constructor(private val clientOptions: ClientOpti val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "user", params.getPathParam(0)) + .addPathSegments("v1", "user", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ViewServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ViewServiceImpl.kt index 8c11e74f..1facbf97 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ViewServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ViewServiceImpl.kt @@ -98,7 +98,7 @@ class ViewServiceImpl internal constructor(private val clientOptions: ClientOpti val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "view", params.getPathParam(0)) + .addPathSegments("v1", "view", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -124,7 +124,7 @@ class ViewServiceImpl internal constructor(private val clientOptions: ClientOpti val request = HttpRequest.builder() .method(HttpMethod.PATCH) - .addPathSegments("v1", "view", params.getPathParam(0)) + .addPathSegments("v1", "view", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) @@ -179,7 +179,7 @@ class ViewServiceImpl internal constructor(private val clientOptions: ClientOpti val request = HttpRequest.builder() .method(HttpMethod.DELETE) - .addPathSegments("v1", "view", params.getPathParam(0)) + .addPathSegments("v1", "view", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/projects/LogServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/projects/LogServiceImpl.kt index d060fec8..2e2f1592 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/projects/LogServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/projects/LogServiceImpl.kt @@ -75,7 +75,7 @@ class LogServiceImpl internal constructor(private val clientOptions: ClientOptio val request = HttpRequest.builder() .method(HttpMethod.POST) - .addPathSegments("v1", "project_logs", params.getPathParam(0), "feedback") + .addPathSegments("v1", "project_logs", params._pathParam(0), "feedback") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) @@ -103,7 +103,7 @@ class LogServiceImpl internal constructor(private val clientOptions: ClientOptio val request = HttpRequest.builder() .method(HttpMethod.GET) - .addPathSegments("v1", "project_logs", params.getPathParam(0), "fetch") + .addPathSegments("v1", "project_logs", params._pathParam(0), "fetch") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) @@ -130,7 +130,7 @@ class LogServiceImpl internal constructor(private val clientOptions: ClientOptio val request = HttpRequest.builder() .method(HttpMethod.POST) - .addPathSegments("v1", "project_logs", params.getPathParam(0), "fetch") + .addPathSegments("v1", "project_logs", params._pathParam(0), "fetch") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) @@ -158,7 +158,7 @@ class LogServiceImpl internal constructor(private val clientOptions: ClientOptio val request = HttpRequest.builder() .method(HttpMethod.POST) - .addPathSegments("v1", "project_logs", params.getPathParam(0), "insert") + .addPathSegments("v1", "project_logs", params._pathParam(0), "insert") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclBatchUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclBatchUpdateParamsTest.kt index fefded29..fd9775ea 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclBatchUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclBatchUpdateParamsTest.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import kotlin.jvm.optionals.getOrNull import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -67,33 +68,29 @@ internal class AclBatchUpdateParamsTest { val body = params._body() assertNotNull(body) - assertThat(body.addAcls()) - .contains( - listOf( - AclBatchUpdateParams.AddAcl.builder() - .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .objectType(AclObjectType.ORGANIZATION) - .groupId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .permission(Permission.CREATE) - .restrictObjectType(AclObjectType.ORGANIZATION) - .roleId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + assertThat(body.addAcls().getOrNull()) + .containsExactly( + AclBatchUpdateParams.AddAcl.builder() + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(AclObjectType.ORGANIZATION) + .groupId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .permission(Permission.CREATE) + .restrictObjectType(AclObjectType.ORGANIZATION) + .roleId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() ) - assertThat(body.removeAcls()) - .contains( - listOf( - AclBatchUpdateParams.RemoveAcl.builder() - .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .objectType(AclObjectType.ORGANIZATION) - .groupId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .permission(Permission.CREATE) - .restrictObjectType(AclObjectType.ORGANIZATION) - .roleId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + assertThat(body.removeAcls().getOrNull()) + .containsExactly( + AclBatchUpdateParams.RemoveAcl.builder() + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(AclObjectType.ORGANIZATION) + .groupId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .permission(Permission.CREATE) + .restrictObjectType(AclObjectType.ORGANIZATION) + .roleId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() ) } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclDeleteParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclDeleteParamsTest.kt index a520f8ce..3f7c31e8 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclDeleteParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclDeleteParamsTest.kt @@ -13,12 +13,11 @@ internal class AclDeleteParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = AclDeleteParams.builder().aclId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - assertThat(params).isNotNull - // path param "aclId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclRetrieveParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclRetrieveParamsTest.kt index 8ad3dfac..0dc6c6be 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclRetrieveParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclRetrieveParamsTest.kt @@ -13,13 +13,12 @@ internal class AclRetrieveParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = AclRetrieveParams.builder().aclId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - assertThat(params).isNotNull - // path param "aclId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretDeleteParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretDeleteParamsTest.kt index 2d9d6f3a..0aecaacb 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretDeleteParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretDeleteParamsTest.kt @@ -13,15 +13,14 @@ internal class AiSecretDeleteParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = AiSecretDeleteParams.builder() .aiSecretId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - assertThat(params).isNotNull - // path param "aiSecretId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretRetrieveParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretRetrieveParamsTest.kt index a9f2f2aa..6fa5c828 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretRetrieveParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretRetrieveParamsTest.kt @@ -13,15 +13,14 @@ internal class AiSecretRetrieveParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = AiSecretRetrieveParams.builder() .aiSecretId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - assertThat(params).isNotNull - // path param "aiSecretId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretUpdateParamsTest.kt index 627ea2bf..2708f3b5 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretUpdateParamsTest.kt @@ -24,6 +24,18 @@ internal class AiSecretUpdateParamsTest { .build() } + @Test + fun pathParams() { + val params = + AiSecretUpdateParams.builder() + .aiSecretId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun body() { val params = @@ -64,17 +76,4 @@ internal class AiSecretUpdateParamsTest { assertNotNull(body) } - - @Test - fun getPathParam() { - val params = - AiSecretUpdateParams.builder() - .aiSecretId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - assertThat(params).isNotNull - // path param "aiSecretId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") - } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParamsTest.kt index f7546c55..4172b7c4 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParamsTest.kt @@ -13,13 +13,12 @@ internal class ApiKeyDeleteParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = ApiKeyDeleteParams.builder().apiKeyId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - assertThat(params).isNotNull - // path param "apiKeyId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ApiKeyRetrieveParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ApiKeyRetrieveParamsTest.kt index f5ca88f6..1612ee3b 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ApiKeyRetrieveParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ApiKeyRetrieveParamsTest.kt @@ -13,13 +13,12 @@ internal class ApiKeyRetrieveParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = ApiKeyRetrieveParams.builder().apiKeyId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - assertThat(params).isNotNull - // path param "apiKeyId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetDeleteParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetDeleteParamsTest.kt index 1d74f765..87b85a35 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetDeleteParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetDeleteParamsTest.kt @@ -13,13 +13,12 @@ internal class DatasetDeleteParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = DatasetDeleteParams.builder().datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - assertThat(params).isNotNull - // path param "datasetId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetEventTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetEventTest.kt index 14d3a5c7..3616a5c2 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetEventTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetEventTest.kt @@ -4,6 +4,7 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import java.time.OffsetDateTime +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -59,6 +60,6 @@ internal class DatasetEventTest { .created("created") .build() ) - assertThat(datasetEvent.tags().get()).containsExactly("string") + assertThat(datasetEvent.tags().getOrNull()).containsExactly("string") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetFeedbackParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetFeedbackParamsTest.kt index 5c8d41e3..f6492260 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetFeedbackParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetFeedbackParamsTest.kt @@ -29,6 +29,19 @@ internal class DatasetFeedbackParamsTest { .build() } + @Test + fun pathParams() { + val params = + DatasetFeedbackParams.builder() + .datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addFeedback(FeedbackDatasetItem.builder().id("id").build()) + .build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun body() { val params = @@ -53,20 +66,18 @@ internal class DatasetFeedbackParamsTest { assertNotNull(body) assertThat(body.feedback()) - .isEqualTo( - listOf( - FeedbackDatasetItem.builder() - .id("id") - .comment("comment") - .metadata( - FeedbackDatasetItem.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) - .build() - ) - .source(FeedbackDatasetItem.Source.APP) - .addTag("string") - .build() - ) + .containsExactly( + FeedbackDatasetItem.builder() + .id("id") + .comment("comment") + .metadata( + FeedbackDatasetItem.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .source(FeedbackDatasetItem.Source.APP) + .addTag("string") + .build() ) } @@ -81,21 +92,6 @@ internal class DatasetFeedbackParamsTest { val body = params._body() assertNotNull(body) - assertThat(body.feedback()) - .isEqualTo(listOf(FeedbackDatasetItem.builder().id("id").build())) - } - - @Test - fun getPathParam() { - val params = - DatasetFeedbackParams.builder() - .datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .addFeedback(FeedbackDatasetItem.builder().id("id").build()) - .build() - assertThat(params).isNotNull - // path param "datasetId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(body.feedback()).containsExactly(FeedbackDatasetItem.builder().id("id").build()) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetFetchParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetFetchParamsTest.kt index 1c31fd85..79504f72 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetFetchParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetFetchParamsTest.kt @@ -19,6 +19,16 @@ internal class DatasetFetchParamsTest { .build() } + @Test + fun pathParams() { + val params = + DatasetFetchParams.builder().datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun queryParams() { val params = @@ -52,15 +62,4 @@ internal class DatasetFetchParamsTest { assertThat(queryParams).isEqualTo(QueryParams.builder().build()) } - - @Test - fun getPathParam() { - val params = - DatasetFetchParams.builder().datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - assertThat(params).isNotNull - // path param "datasetId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") - } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetFetchPostParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetFetchPostParamsTest.kt index 53eeec48..e2b5f2d9 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetFetchPostParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetFetchPostParamsTest.kt @@ -20,6 +20,18 @@ internal class DatasetFetchPostParamsTest { .build() } + @Test + fun pathParams() { + val params = + DatasetFetchPostParams.builder() + .datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun body() { val params = @@ -53,17 +65,4 @@ internal class DatasetFetchPostParamsTest { assertNotNull(body) } - - @Test - fun getPathParam() { - val params = - DatasetFetchPostParams.builder() - .datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - assertThat(params).isNotNull - // path param "datasetId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") - } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetInsertParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetInsertParamsTest.kt index 4b535b10..901f6f82 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetInsertParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetInsertParamsTest.kt @@ -43,6 +43,19 @@ internal class DatasetInsertParamsTest { .build() } + @Test + fun pathParams() { + val params = + DatasetInsertParams.builder() + .datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addEvent(InsertDatasetEvent.builder().build()) + .build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun body() { val params = @@ -80,33 +93,31 @@ internal class DatasetInsertParamsTest { assertNotNull(body) assertThat(body.events()) - .isEqualTo( - listOf( - InsertDatasetEvent.builder() - .id("id") - ._isMerge(true) - .addMergePath(listOf("string")) - ._objectDelete(true) - ._parentId("_parent_id") - .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) - .expected(JsonValue.from(mapOf())) - .input(JsonValue.from(mapOf())) - .metadata(InsertDatasetEvent.Metadata.builder().model("model").build()) - .origin( - ObjectReference.builder() - .id("id") - ._xactId("_xact_id") - .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .objectType(ObjectReference.ObjectType.EXPERIMENT) - .created("created") - .build() - ) - .rootSpanId("root_span_id") - .spanId("span_id") - .addSpanParent("string") - .addTag("string") - .build() - ) + .containsExactly( + InsertDatasetEvent.builder() + .id("id") + ._isMerge(true) + .addMergePath(listOf("string")) + ._objectDelete(true) + ._parentId("_parent_id") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .expected(JsonValue.from(mapOf())) + .input(JsonValue.from(mapOf())) + .metadata(InsertDatasetEvent.Metadata.builder().model("model").build()) + .origin( + ObjectReference.builder() + .id("id") + ._xactId("_xact_id") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(ObjectReference.ObjectType.EXPERIMENT) + .created("created") + .build() + ) + .rootSpanId("root_span_id") + .spanId("span_id") + .addSpanParent("string") + .addTag("string") + .build() ) } @@ -121,20 +132,6 @@ internal class DatasetInsertParamsTest { val body = params._body() assertNotNull(body) - assertThat(body.events()).isEqualTo(listOf(InsertDatasetEvent.builder().build())) - } - - @Test - fun getPathParam() { - val params = - DatasetInsertParams.builder() - .datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .addEvent(InsertDatasetEvent.builder().build()) - .build() - assertThat(params).isNotNull - // path param "datasetId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(body.events()).containsExactly(InsertDatasetEvent.builder().build()) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetRetrieveParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetRetrieveParamsTest.kt index 147e6451..1cdff551 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetRetrieveParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetRetrieveParamsTest.kt @@ -13,15 +13,14 @@ internal class DatasetRetrieveParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = DatasetRetrieveParams.builder() .datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - assertThat(params).isNotNull - // path param "datasetId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetSummarizeParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetSummarizeParamsTest.kt index 24bc6c0f..49062a2c 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetSummarizeParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetSummarizeParamsTest.kt @@ -16,6 +16,18 @@ internal class DatasetSummarizeParamsTest { .build() } + @Test + fun pathParams() { + val params = + DatasetSummarizeParams.builder() + .datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun queryParams() { val params = @@ -41,17 +53,4 @@ internal class DatasetSummarizeParamsTest { assertThat(queryParams).isEqualTo(QueryParams.builder().build()) } - - @Test - fun getPathParam() { - val params = - DatasetSummarizeParams.builder() - .datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - assertThat(params).isNotNull - // path param "datasetId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") - } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetUpdateParamsTest.kt index ebdf0e4f..c90a33a0 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetUpdateParamsTest.kt @@ -23,6 +23,16 @@ internal class DatasetUpdateParamsTest { .build() } + @Test + fun pathParams() { + val params = + DatasetUpdateParams.builder().datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun body() { val params = @@ -59,15 +69,4 @@ internal class DatasetUpdateParamsTest { assertNotNull(body) } - - @Test - fun getPathParam() { - val params = - DatasetUpdateParams.builder().datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - assertThat(params).isNotNull - // path param "datasetId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") - } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarDeleteParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarDeleteParamsTest.kt index e7c988b4..80887f78 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarDeleteParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarDeleteParamsTest.kt @@ -13,13 +13,12 @@ internal class EnvVarDeleteParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = EnvVarDeleteParams.builder().envVarId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - assertThat(params).isNotNull - // path param "envVarId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarRetrieveParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarRetrieveParamsTest.kt index d2eee241..b3cefe22 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarRetrieveParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarRetrieveParamsTest.kt @@ -13,13 +13,12 @@ internal class EnvVarRetrieveParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = EnvVarRetrieveParams.builder().envVarId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - assertThat(params).isNotNull - // path param "envVarId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarUpdateParamsTest.kt index 81bdf42a..4198a5c5 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarUpdateParamsTest.kt @@ -18,46 +18,45 @@ internal class EnvVarUpdateParamsTest { } @Test - fun body() { + fun pathParams() { val params = EnvVarUpdateParams.builder() .envVarId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .name("name") - .value("value") .build() - val body = params._body() - - assertNotNull(body) - assertThat(body.name()).isEqualTo("name") - assertThat(body.value()).contains("value") + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") } @Test - fun bodyWithoutOptionalFields() { + fun body() { val params = EnvVarUpdateParams.builder() .envVarId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .name("name") + .value("value") .build() val body = params._body() assertNotNull(body) assertThat(body.name()).isEqualTo("name") + assertThat(body.value()).contains("value") } @Test - fun getPathParam() { + fun bodyWithoutOptionalFields() { val params = EnvVarUpdateParams.builder() .envVarId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .name("name") .build() - assertThat(params).isNotNull - // path param "envVarId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + + val body = params._body() + + assertNotNull(body) + assertThat(body.name()).isEqualTo("name") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EvalCreateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EvalCreateParamsTest.kt index ec0f8d22..cf8b33be 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EvalCreateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EvalCreateParamsTest.kt @@ -190,14 +190,12 @@ internal class EvalCreateParamsTest { ) assertThat(body.projectId()).isEqualTo("project_id") assertThat(body.scores()) - .isEqualTo( - listOf( - EvalCreateParams.Score.ofFunctionId( - EvalCreateParams.Score.FunctionId.builder() - .functionId("function_id") - .version("version") - .build() - ) + .containsExactly( + EvalCreateParams.Score.ofFunctionId( + EvalCreateParams.Score.FunctionId.builder() + .functionId("function_id") + .version("version") + .build() ) ) assertThat(body.task()) @@ -292,13 +290,9 @@ internal class EvalCreateParamsTest { ) assertThat(body.projectId()).isEqualTo("project_id") assertThat(body.scores()) - .isEqualTo( - listOf( - EvalCreateParams.Score.ofFunctionId( - EvalCreateParams.Score.FunctionId.builder() - .functionId("function_id") - .build() - ) + .containsExactly( + EvalCreateParams.Score.ofFunctionId( + EvalCreateParams.Score.FunctionId.builder().functionId("function_id").build() ) ) assertThat(body.task()) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentDeleteParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentDeleteParamsTest.kt index cc7edd11..d3aa984d 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentDeleteParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentDeleteParamsTest.kt @@ -15,15 +15,14 @@ internal class ExperimentDeleteParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = ExperimentDeleteParams.builder() .experimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - assertThat(params).isNotNull - // path param "experimentId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentEventTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentEventTest.kt index bc31377c..09e01ad6 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentEventTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentEventTest.kt @@ -4,6 +4,7 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import java.time.OffsetDateTime +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -118,7 +119,7 @@ internal class ExperimentEventTest { ) assertThat(experimentEvent.spanAttributes()) .contains(SpanAttributes.builder().name("name").type(SpanType.LLM).build()) - assertThat(experimentEvent.spanParents().get()).containsExactly("string") - assertThat(experimentEvent.tags().get()).containsExactly("string") + assertThat(experimentEvent.spanParents().getOrNull()).containsExactly("string") + assertThat(experimentEvent.tags().getOrNull()).containsExactly("string") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParamsTest.kt index 5ce9c787..f7220d83 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParamsTest.kt @@ -35,6 +35,19 @@ internal class ExperimentFeedbackParamsTest { .build() } + @Test + fun pathParams() { + val params = + ExperimentFeedbackParams.builder() + .experimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addFeedback(FeedbackExperimentItem.builder().id("id").build()) + .build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun body() { val params = @@ -65,26 +78,24 @@ internal class ExperimentFeedbackParamsTest { assertNotNull(body) assertThat(body.feedback()) - .isEqualTo( - listOf( - FeedbackExperimentItem.builder() - .id("id") - .comment("comment") - .expected(JsonValue.from(mapOf())) - .metadata( - FeedbackExperimentItem.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) - .build() - ) - .scores( - FeedbackExperimentItem.Scores.builder() - .putAdditionalProperty("foo", JsonValue.from(0)) - .build() - ) - .source(FeedbackExperimentItem.Source.APP) - .addTag("string") - .build() - ) + .containsExactly( + FeedbackExperimentItem.builder() + .id("id") + .comment("comment") + .expected(JsonValue.from(mapOf())) + .metadata( + FeedbackExperimentItem.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .scores( + FeedbackExperimentItem.Scores.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .source(FeedbackExperimentItem.Source.APP) + .addTag("string") + .build() ) } @@ -100,20 +111,6 @@ internal class ExperimentFeedbackParamsTest { assertNotNull(body) assertThat(body.feedback()) - .isEqualTo(listOf(FeedbackExperimentItem.builder().id("id").build())) - } - - @Test - fun getPathParam() { - val params = - ExperimentFeedbackParams.builder() - .experimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .addFeedback(FeedbackExperimentItem.builder().id("id").build()) - .build() - assertThat(params).isNotNull - // path param "experimentId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + .containsExactly(FeedbackExperimentItem.builder().id("id").build()) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentFetchParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentFetchParamsTest.kt index a4d0d229..70160fd1 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentFetchParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentFetchParamsTest.kt @@ -19,6 +19,18 @@ internal class ExperimentFetchParamsTest { .build() } + @Test + fun pathParams() { + val params = + ExperimentFetchParams.builder() + .experimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun queryParams() { val params = @@ -54,17 +66,4 @@ internal class ExperimentFetchParamsTest { assertThat(queryParams).isEqualTo(QueryParams.builder().build()) } - - @Test - fun getPathParam() { - val params = - ExperimentFetchParams.builder() - .experimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - assertThat(params).isNotNull - // path param "experimentId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") - } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParamsTest.kt index d8445769..29230582 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParamsTest.kt @@ -20,6 +20,18 @@ internal class ExperimentFetchPostParamsTest { .build() } + @Test + fun pathParams() { + val params = + ExperimentFetchPostParams.builder() + .experimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun body() { val params = @@ -53,17 +65,4 @@ internal class ExperimentFetchPostParamsTest { assertNotNull(body) } - - @Test - fun getPathParam() { - val params = - ExperimentFetchPostParams.builder() - .experimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - assertThat(params).isNotNull - // path param "experimentId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") - } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentInsertParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentInsertParamsTest.kt index aeaadaf0..be527a66 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentInsertParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentInsertParamsTest.kt @@ -72,6 +72,19 @@ internal class ExperimentInsertParamsTest { .build() } + @Test + fun pathParams() { + val params = + ExperimentInsertParams.builder() + .experimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addEvent(InsertExperimentEvent.builder().build()) + .build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun body() { val params = @@ -138,62 +151,60 @@ internal class ExperimentInsertParamsTest { assertNotNull(body) assertThat(body.events()) - .isEqualTo( - listOf( - InsertExperimentEvent.builder() - .id("id") - ._isMerge(true) - .addMergePath(listOf("string")) - ._objectDelete(true) - ._parentId("_parent_id") - .context( - InsertExperimentEvent.Context.builder() - .callerFilename("caller_filename") - .callerFunctionname("caller_functionname") - .callerLineno(0L) - .build() - ) - .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) - .error(JsonValue.from(mapOf())) - .expected(JsonValue.from(mapOf())) - .input(JsonValue.from(mapOf())) - .metadata(InsertExperimentEvent.Metadata.builder().model("model").build()) - .metrics( - InsertExperimentEvent.Metrics.builder() - .callerFilename(JsonValue.from(mapOf())) - .callerFunctionname(JsonValue.from(mapOf())) - .callerLineno(JsonValue.from(mapOf())) - .completionTokens(0L) - .end(0.0) - .promptTokens(0L) - .start(0.0) - .tokens(0L) - .build() - ) - .origin( - ObjectReference.builder() - .id("id") - ._xactId("_xact_id") - .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .objectType(ObjectReference.ObjectType.EXPERIMENT) - .created("created") - .build() - ) - .output(JsonValue.from(mapOf())) - .rootSpanId("root_span_id") - .scores( - InsertExperimentEvent.Scores.builder() - .putAdditionalProperty("foo", JsonValue.from(0)) - .build() - ) - .spanAttributes( - SpanAttributes.builder().name("name").type(SpanType.LLM).build() - ) - .spanId("span_id") - .addSpanParent("string") - .addTag("string") - .build() - ) + .containsExactly( + InsertExperimentEvent.builder() + .id("id") + ._isMerge(true) + .addMergePath(listOf("string")) + ._objectDelete(true) + ._parentId("_parent_id") + .context( + InsertExperimentEvent.Context.builder() + .callerFilename("caller_filename") + .callerFunctionname("caller_functionname") + .callerLineno(0L) + .build() + ) + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .error(JsonValue.from(mapOf())) + .expected(JsonValue.from(mapOf())) + .input(JsonValue.from(mapOf())) + .metadata(InsertExperimentEvent.Metadata.builder().model("model").build()) + .metrics( + InsertExperimentEvent.Metrics.builder() + .callerFilename(JsonValue.from(mapOf())) + .callerFunctionname(JsonValue.from(mapOf())) + .callerLineno(JsonValue.from(mapOf())) + .completionTokens(0L) + .end(0.0) + .promptTokens(0L) + .start(0.0) + .tokens(0L) + .build() + ) + .origin( + ObjectReference.builder() + .id("id") + ._xactId("_xact_id") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(ObjectReference.ObjectType.EXPERIMENT) + .created("created") + .build() + ) + .output(JsonValue.from(mapOf())) + .rootSpanId("root_span_id") + .scores( + InsertExperimentEvent.Scores.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .spanAttributes( + SpanAttributes.builder().name("name").type(SpanType.LLM).build() + ) + .spanId("span_id") + .addSpanParent("string") + .addTag("string") + .build() ) } @@ -208,20 +219,6 @@ internal class ExperimentInsertParamsTest { val body = params._body() assertNotNull(body) - assertThat(body.events()).isEqualTo(listOf(InsertExperimentEvent.builder().build())) - } - - @Test - fun getPathParam() { - val params = - ExperimentInsertParams.builder() - .experimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .addEvent(InsertExperimentEvent.builder().build()) - .build() - assertThat(params).isNotNull - // path param "experimentId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(body.events()).containsExactly(InsertExperimentEvent.builder().build()) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentRetrieveParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentRetrieveParamsTest.kt index 435a99fd..26795ef7 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentRetrieveParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentRetrieveParamsTest.kt @@ -15,15 +15,14 @@ internal class ExperimentRetrieveParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = ExperimentRetrieveParams.builder() .experimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - assertThat(params).isNotNull - // path param "experimentId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentSummarizeParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentSummarizeParamsTest.kt index 3260545d..c5599fa2 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentSummarizeParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentSummarizeParamsTest.kt @@ -17,6 +17,18 @@ internal class ExperimentSummarizeParamsTest { .build() } + @Test + fun pathParams() { + val params = + ExperimentSummarizeParams.builder() + .experimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun queryParams() { val params = @@ -48,17 +60,4 @@ internal class ExperimentSummarizeParamsTest { assertThat(queryParams).isEqualTo(QueryParams.builder().build()) } - - @Test - fun getPathParam() { - val params = - ExperimentSummarizeParams.builder() - .experimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - assertThat(params).isNotNull - // path param "experimentId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") - } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentUpdateParamsTest.kt index 2284d934..379cb233 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentUpdateParamsTest.kt @@ -40,6 +40,18 @@ internal class ExperimentUpdateParamsTest { .build() } + @Test + fun pathParams() { + val params = + ExperimentUpdateParams.builder() + .experimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun body() { val params = @@ -113,17 +125,4 @@ internal class ExperimentUpdateParamsTest { assertNotNull(body) } - - @Test - fun getPathParam() { - val params = - ExperimentUpdateParams.builder() - .experimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - assertThat(params).isNotNull - // path param "experimentId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") - } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackDatasetItemTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackDatasetItemTest.kt index b10a7fce..52cac9b6 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackDatasetItemTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackDatasetItemTest.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -32,6 +33,6 @@ internal class FeedbackDatasetItemTest { .build() ) assertThat(feedbackDatasetItem.source()).contains(FeedbackDatasetItem.Source.APP) - assertThat(feedbackDatasetItem.tags().get()).containsExactly("string") + assertThat(feedbackDatasetItem.tags().getOrNull()).containsExactly("string") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackExperimentItemTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackExperimentItemTest.kt index 2b36a2b7..cfbe1bbe 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackExperimentItemTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackExperimentItemTest.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -46,6 +47,6 @@ internal class FeedbackExperimentItemTest { .build() ) assertThat(feedbackExperimentItem.source()).contains(FeedbackExperimentItem.Source.APP) - assertThat(feedbackExperimentItem.tags().get()).containsExactly("string") + assertThat(feedbackExperimentItem.tags().getOrNull()).containsExactly("string") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItemTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItemTest.kt index 6fea45de..91358ac0 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItemTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItemTest.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -46,6 +47,6 @@ internal class FeedbackProjectLogsItemTest { .build() ) assertThat(feedbackProjectLogsItem.source()).contains(FeedbackProjectLogsItem.Source.APP) - assertThat(feedbackProjectLogsItem.tags().get()).containsExactly("string") + assertThat(feedbackProjectLogsItem.tags().getOrNull()).containsExactly("string") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionCreateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionCreateParamsTest.kt index a4747bcf..45b97b27 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionCreateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionCreateParamsTest.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import kotlin.jvm.optionals.getOrNull import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -339,7 +340,7 @@ internal class FunctionCreateParamsTest { ) .build() ) - assertThat(body.tags()).contains(listOf("string")) + assertThat(body.tags().getOrNull()).containsExactly("string") } @Test diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionDeleteParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionDeleteParamsTest.kt index 4b8a7c19..3e0df519 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionDeleteParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionDeleteParamsTest.kt @@ -13,15 +13,14 @@ internal class FunctionDeleteParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = FunctionDeleteParams.builder() .functionId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - assertThat(params).isNotNull - // path param "functionId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionInvokeParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionInvokeParamsTest.kt index 988dc6e4..40aeb417 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionInvokeParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionInvokeParamsTest.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import kotlin.jvm.optionals.getOrNull import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -53,6 +54,18 @@ internal class FunctionInvokeParamsTest { .build() } + @Test + fun pathParams() { + val params = + FunctionInvokeParams.builder() + .functionId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun body() { val params = @@ -102,16 +115,14 @@ internal class FunctionInvokeParamsTest { assertNotNull(body) assertThat(body._expected()).isEqualTo(JsonValue.from(mapOf())) assertThat(body._input()).isEqualTo(JsonValue.from(mapOf())) - assertThat(body.messages()) - .contains( - listOf( - FunctionInvokeParams.Message.ofSystem( - FunctionInvokeParams.Message.System.builder() - .role(FunctionInvokeParams.Message.System.Role.SYSTEM) - .content("content") - .name("name") - .build() - ) + assertThat(body.messages().getOrNull()) + .containsExactly( + FunctionInvokeParams.Message.ofSystem( + FunctionInvokeParams.Message.System.builder() + .role(FunctionInvokeParams.Message.System.Role.SYSTEM) + .content("content") + .name("name") + .build() ) ) assertThat(body.metadata()) @@ -159,17 +170,4 @@ internal class FunctionInvokeParamsTest { assertNotNull(body) } - - @Test - fun getPathParam() { - val params = - FunctionInvokeParams.builder() - .functionId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - assertThat(params).isNotNull - // path param "functionId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") - } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionReplaceParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionReplaceParamsTest.kt index a1c6af81..af90f34c 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionReplaceParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionReplaceParamsTest.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import kotlin.jvm.optionals.getOrNull import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -339,7 +340,7 @@ internal class FunctionReplaceParamsTest { ) .build() ) - assertThat(body.tags()).contains(listOf("string")) + assertThat(body.tags().getOrNull()).containsExactly("string") } @Test diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionRetrieveParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionRetrieveParamsTest.kt index 9890c9f3..fd70fae8 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionRetrieveParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionRetrieveParamsTest.kt @@ -13,15 +13,14 @@ internal class FunctionRetrieveParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = FunctionRetrieveParams.builder() .functionId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - assertThat(params).isNotNull - // path param "functionId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionTest.kt index b42ee0e0..cf3ad0e4 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionTest.kt @@ -4,6 +4,7 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import java.time.OffsetDateTime +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -248,6 +249,6 @@ internal class FunctionTest { ) .build() ) - assertThat(function.tags().get()).containsExactly("string") + assertThat(function.tags().getOrNull()).containsExactly("string") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionUpdateParamsTest.kt index 261982cd..94a7bbd5 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionUpdateParamsTest.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import kotlin.jvm.optionals.getOrNull import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -103,6 +104,18 @@ internal class FunctionUpdateParamsTest { .build() } + @Test + fun pathParams() { + val params = + FunctionUpdateParams.builder() + .functionId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun body() { val params = @@ -291,7 +304,7 @@ internal class FunctionUpdateParamsTest { ) .build() ) - assertThat(body.tags()).contains(listOf("string")) + assertThat(body.tags().getOrNull()).containsExactly("string") } @Test @@ -305,17 +318,4 @@ internal class FunctionUpdateParamsTest { assertNotNull(body) } - - @Test - fun getPathParam() { - val params = - FunctionUpdateParams.builder() - .functionId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - assertThat(params).isNotNull - // path param "functionId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") - } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupCreateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupCreateParamsTest.kt index 4707e762..9fabfeab 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupCreateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupCreateParamsTest.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import kotlin.jvm.optionals.getOrNull import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -35,8 +36,10 @@ internal class GroupCreateParamsTest { assertNotNull(body) assertThat(body.name()).isEqualTo("x") assertThat(body.description()).contains("description") - assertThat(body.memberGroups()).contains(listOf("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")) - assertThat(body.memberUsers()).contains(listOf("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")) + assertThat(body.memberGroups().getOrNull()) + .containsExactly("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + assertThat(body.memberUsers().getOrNull()) + .containsExactly("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.orgName()).contains("org_name") } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupDeleteParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupDeleteParamsTest.kt index 362fe3f6..3f194aea 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupDeleteParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupDeleteParamsTest.kt @@ -13,13 +13,12 @@ internal class GroupDeleteParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = GroupDeleteParams.builder().groupId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - assertThat(params).isNotNull - // path param "groupId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupReplaceParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupReplaceParamsTest.kt index d5c3f0ec..4b1a8be3 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupReplaceParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupReplaceParamsTest.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import kotlin.jvm.optionals.getOrNull import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -35,8 +36,10 @@ internal class GroupReplaceParamsTest { assertNotNull(body) assertThat(body.name()).isEqualTo("x") assertThat(body.description()).contains("description") - assertThat(body.memberGroups()).contains(listOf("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")) - assertThat(body.memberUsers()).contains(listOf("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")) + assertThat(body.memberGroups().getOrNull()) + .containsExactly("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + assertThat(body.memberUsers().getOrNull()) + .containsExactly("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.orgName()).contains("org_name") } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupRetrieveParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupRetrieveParamsTest.kt index ea355d6a..88125d11 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupRetrieveParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupRetrieveParamsTest.kt @@ -13,13 +13,12 @@ internal class GroupRetrieveParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = GroupRetrieveParams.builder().groupId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - assertThat(params).isNotNull - // path param "groupId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupTest.kt index 235fb2a1..360283d5 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupTest.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.models import java.time.OffsetDateTime +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -29,9 +30,9 @@ internal class GroupTest { assertThat(group.created()).contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) assertThat(group.deletedAt()).contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) assertThat(group.description()).contains("description") - assertThat(group.memberGroups().get()) + assertThat(group.memberGroups().getOrNull()) .containsExactly("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - assertThat(group.memberUsers().get()) + assertThat(group.memberUsers().getOrNull()) .containsExactly("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(group.userId()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupUpdateParamsTest.kt index ece1b27d..62745599 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupUpdateParamsTest.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import kotlin.jvm.optionals.getOrNull import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -21,6 +22,16 @@ internal class GroupUpdateParamsTest { .build() } + @Test + fun pathParams() { + val params = + GroupUpdateParams.builder().groupId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun body() { val params = @@ -37,14 +48,16 @@ internal class GroupUpdateParamsTest { val body = params._body() assertNotNull(body) - assertThat(body.addMemberGroups()).contains(listOf("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")) - assertThat(body.addMemberUsers()).contains(listOf("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")) + assertThat(body.addMemberGroups().getOrNull()) + .containsExactly("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + assertThat(body.addMemberUsers().getOrNull()) + .containsExactly("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.description()).contains("description") assertThat(body.name()).contains("x") - assertThat(body.removeMemberGroups()) - .contains(listOf("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")) - assertThat(body.removeMemberUsers()) - .contains(listOf("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")) + assertThat(body.removeMemberGroups().getOrNull()) + .containsExactly("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + assertThat(body.removeMemberUsers().getOrNull()) + .containsExactly("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") } @Test @@ -56,15 +69,4 @@ internal class GroupUpdateParamsTest { assertNotNull(body) } - - @Test - fun getPathParam() { - val params = - GroupUpdateParams.builder().groupId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - assertThat(params).isNotNull - // path param "groupId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") - } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertDatasetEventTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertDatasetEventTest.kt index 176a9e81..31c116a5 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertDatasetEventTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertDatasetEventTest.kt @@ -4,6 +4,7 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import java.time.OffsetDateTime +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -39,7 +40,7 @@ internal class InsertDatasetEventTest { assertThat(insertDatasetEvent).isNotNull assertThat(insertDatasetEvent.id()).contains("id") assertThat(insertDatasetEvent._isMerge()).contains(true) - assertThat(insertDatasetEvent._mergePaths().get()).containsExactly(listOf("string")) + assertThat(insertDatasetEvent._mergePaths().getOrNull()).containsExactly(listOf("string")) assertThat(insertDatasetEvent._objectDelete()).contains(true) assertThat(insertDatasetEvent._parentId()).contains("_parent_id") assertThat(insertDatasetEvent.created()) @@ -60,7 +61,7 @@ internal class InsertDatasetEventTest { ) assertThat(insertDatasetEvent.rootSpanId()).contains("root_span_id") assertThat(insertDatasetEvent.spanId()).contains("span_id") - assertThat(insertDatasetEvent.spanParents().get()).containsExactly("string") - assertThat(insertDatasetEvent.tags().get()).containsExactly("string") + assertThat(insertDatasetEvent.spanParents().getOrNull()).containsExactly("string") + assertThat(insertDatasetEvent.tags().getOrNull()).containsExactly("string") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertExperimentEventTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertExperimentEventTest.kt index 3f52dc7f..127c3e49 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertExperimentEventTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertExperimentEventTest.kt @@ -4,6 +4,7 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import java.time.OffsetDateTime +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -66,7 +67,8 @@ internal class InsertExperimentEventTest { assertThat(insertExperimentEvent).isNotNull assertThat(insertExperimentEvent.id()).contains("id") assertThat(insertExperimentEvent._isMerge()).contains(true) - assertThat(insertExperimentEvent._mergePaths().get()).containsExactly(listOf("string")) + assertThat(insertExperimentEvent._mergePaths().getOrNull()) + .containsExactly(listOf("string")) assertThat(insertExperimentEvent._objectDelete()).contains(true) assertThat(insertExperimentEvent._parentId()).contains("_parent_id") assertThat(insertExperimentEvent.context()) @@ -119,7 +121,7 @@ internal class InsertExperimentEventTest { assertThat(insertExperimentEvent.spanAttributes()) .contains(SpanAttributes.builder().name("name").type(SpanType.LLM).build()) assertThat(insertExperimentEvent.spanId()).contains("span_id") - assertThat(insertExperimentEvent.spanParents().get()).containsExactly("string") - assertThat(insertExperimentEvent.tags().get()).containsExactly("string") + assertThat(insertExperimentEvent.spanParents().getOrNull()).containsExactly("string") + assertThat(insertExperimentEvent.tags().getOrNull()).containsExactly("string") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertProjectLogsEventTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertProjectLogsEventTest.kt index b3812878..76faf6a0 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertProjectLogsEventTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertProjectLogsEventTest.kt @@ -4,6 +4,7 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import java.time.OffsetDateTime +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -66,7 +67,8 @@ internal class InsertProjectLogsEventTest { assertThat(insertProjectLogsEvent).isNotNull assertThat(insertProjectLogsEvent.id()).contains("id") assertThat(insertProjectLogsEvent._isMerge()).contains(true) - assertThat(insertProjectLogsEvent._mergePaths().get()).containsExactly(listOf("string")) + assertThat(insertProjectLogsEvent._mergePaths().getOrNull()) + .containsExactly(listOf("string")) assertThat(insertProjectLogsEvent._objectDelete()).contains(true) assertThat(insertProjectLogsEvent._parentId()).contains("_parent_id") assertThat(insertProjectLogsEvent.context()) @@ -119,7 +121,7 @@ internal class InsertProjectLogsEventTest { assertThat(insertProjectLogsEvent.spanAttributes()) .contains(SpanAttributes.builder().name("name").type(SpanType.LLM).build()) assertThat(insertProjectLogsEvent.spanId()).contains("span_id") - assertThat(insertProjectLogsEvent.spanParents().get()).containsExactly("string") - assertThat(insertProjectLogsEvent.tags().get()).containsExactly("string") + assertThat(insertProjectLogsEvent.spanParents().getOrNull()).containsExactly("string") + assertThat(insertProjectLogsEvent.tags().getOrNull()).containsExactly("string") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OnlineScoreConfigTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OnlineScoreConfigTest.kt index 01f4d508..5fe9bcbb 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OnlineScoreConfigTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OnlineScoreConfigTest.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -33,6 +34,6 @@ internal class OnlineScoreConfigTest { ) ) assertThat(onlineScoreConfig.applyToRootSpan()).contains(true) - assertThat(onlineScoreConfig.applyToSpanNames().get()).containsExactly("string") + assertThat(onlineScoreConfig.applyToSpanNames().getOrNull()).containsExactly("string") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationDeleteParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationDeleteParamsTest.kt index 7bd8b264..365faa22 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationDeleteParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationDeleteParamsTest.kt @@ -15,15 +15,14 @@ internal class OrganizationDeleteParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = OrganizationDeleteParams.builder() .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - assertThat(params).isNotNull - // path param "organizationId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationRetrieveParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationRetrieveParamsTest.kt index b0f6faaf..bb59a8e4 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationRetrieveParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationRetrieveParamsTest.kt @@ -15,15 +15,14 @@ internal class OrganizationRetrieveParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = OrganizationRetrieveParams.builder() .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - assertThat(params).isNotNull - // path param "organizationId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationUpdateParamsTest.kt index f1cf977a..b36c421b 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationUpdateParamsTest.kt @@ -20,6 +20,18 @@ internal class OrganizationUpdateParamsTest { .build() } + @Test + fun pathParams() { + val params = + OrganizationUpdateParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun body() { val params = @@ -53,17 +65,4 @@ internal class OrganizationUpdateParamsTest { assertNotNull(body) } - - @Test - fun getPathParam() { - val params = - OrganizationUpdateParams.builder() - .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - assertThat(params).isNotNull - // path param "organizationId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") - } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectDeleteParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectDeleteParamsTest.kt index 3e30198e..47a71480 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectDeleteParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectDeleteParamsTest.kt @@ -13,13 +13,12 @@ internal class ProjectDeleteParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = ProjectDeleteParams.builder().projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - assertThat(params).isNotNull - // path param "projectId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParamsTest.kt index 516e71e3..c6c6141e 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParamsTest.kt @@ -35,6 +35,19 @@ internal class ProjectLogFeedbackParamsTest { .build() } + @Test + fun pathParams() { + val params = + ProjectLogFeedbackParams.builder() + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addFeedback(FeedbackProjectLogsItem.builder().id("id").build()) + .build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun body() { val params = @@ -65,26 +78,24 @@ internal class ProjectLogFeedbackParamsTest { assertNotNull(body) assertThat(body.feedback()) - .isEqualTo( - listOf( - FeedbackProjectLogsItem.builder() - .id("id") - .comment("comment") - .expected(JsonValue.from(mapOf())) - .metadata( - FeedbackProjectLogsItem.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) - .build() - ) - .scores( - FeedbackProjectLogsItem.Scores.builder() - .putAdditionalProperty("foo", JsonValue.from(0)) - .build() - ) - .source(FeedbackProjectLogsItem.Source.APP) - .addTag("string") - .build() - ) + .containsExactly( + FeedbackProjectLogsItem.builder() + .id("id") + .comment("comment") + .expected(JsonValue.from(mapOf())) + .metadata( + FeedbackProjectLogsItem.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .scores( + FeedbackProjectLogsItem.Scores.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .source(FeedbackProjectLogsItem.Source.APP) + .addTag("string") + .build() ) } @@ -100,20 +111,6 @@ internal class ProjectLogFeedbackParamsTest { assertNotNull(body) assertThat(body.feedback()) - .isEqualTo(listOf(FeedbackProjectLogsItem.builder().id("id").build())) - } - - @Test - fun getPathParam() { - val params = - ProjectLogFeedbackParams.builder() - .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .addFeedback(FeedbackProjectLogsItem.builder().id("id").build()) - .build() - assertThat(params).isNotNull - // path param "projectId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + .containsExactly(FeedbackProjectLogsItem.builder().id("id").build()) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogFetchParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogFetchParamsTest.kt index 2f305737..545e215e 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogFetchParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogFetchParamsTest.kt @@ -19,6 +19,18 @@ internal class ProjectLogFetchParamsTest { .build() } + @Test + fun pathParams() { + val params = + ProjectLogFetchParams.builder() + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun queryParams() { val params = @@ -54,17 +66,4 @@ internal class ProjectLogFetchParamsTest { assertThat(queryParams).isEqualTo(QueryParams.builder().build()) } - - @Test - fun getPathParam() { - val params = - ProjectLogFetchParams.builder() - .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - assertThat(params).isNotNull - // path param "projectId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") - } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParamsTest.kt index 6bed5b0e..ec1fbe5d 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParamsTest.kt @@ -20,6 +20,18 @@ internal class ProjectLogFetchPostParamsTest { .build() } + @Test + fun pathParams() { + val params = + ProjectLogFetchPostParams.builder() + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun body() { val params = @@ -53,17 +65,4 @@ internal class ProjectLogFetchPostParamsTest { assertNotNull(body) } - - @Test - fun getPathParam() { - val params = - ProjectLogFetchPostParams.builder() - .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - assertThat(params).isNotNull - // path param "projectId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") - } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogInsertParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogInsertParamsTest.kt index d238976b..602502ea 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogInsertParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogInsertParamsTest.kt @@ -72,6 +72,19 @@ internal class ProjectLogInsertParamsTest { .build() } + @Test + fun pathParams() { + val params = + ProjectLogInsertParams.builder() + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addEvent(InsertProjectLogsEvent.builder().build()) + .build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun body() { val params = @@ -138,62 +151,60 @@ internal class ProjectLogInsertParamsTest { assertNotNull(body) assertThat(body.events()) - .isEqualTo( - listOf( - InsertProjectLogsEvent.builder() - .id("id") - ._isMerge(true) - .addMergePath(listOf("string")) - ._objectDelete(true) - ._parentId("_parent_id") - .context( - InsertProjectLogsEvent.Context.builder() - .callerFilename("caller_filename") - .callerFunctionname("caller_functionname") - .callerLineno(0L) - .build() - ) - .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) - .error(JsonValue.from(mapOf())) - .expected(JsonValue.from(mapOf())) - .input(JsonValue.from(mapOf())) - .metadata(InsertProjectLogsEvent.Metadata.builder().model("model").build()) - .metrics( - InsertProjectLogsEvent.Metrics.builder() - .callerFilename(JsonValue.from(mapOf())) - .callerFunctionname(JsonValue.from(mapOf())) - .callerLineno(JsonValue.from(mapOf())) - .completionTokens(0L) - .end(0.0) - .promptTokens(0L) - .start(0.0) - .tokens(0L) - .build() - ) - .origin( - ObjectReference.builder() - .id("id") - ._xactId("_xact_id") - .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .objectType(ObjectReference.ObjectType.EXPERIMENT) - .created("created") - .build() - ) - .output(JsonValue.from(mapOf())) - .rootSpanId("root_span_id") - .scores( - InsertProjectLogsEvent.Scores.builder() - .putAdditionalProperty("foo", JsonValue.from(0)) - .build() - ) - .spanAttributes( - SpanAttributes.builder().name("name").type(SpanType.LLM).build() - ) - .spanId("span_id") - .addSpanParent("string") - .addTag("string") - .build() - ) + .containsExactly( + InsertProjectLogsEvent.builder() + .id("id") + ._isMerge(true) + .addMergePath(listOf("string")) + ._objectDelete(true) + ._parentId("_parent_id") + .context( + InsertProjectLogsEvent.Context.builder() + .callerFilename("caller_filename") + .callerFunctionname("caller_functionname") + .callerLineno(0L) + .build() + ) + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .error(JsonValue.from(mapOf())) + .expected(JsonValue.from(mapOf())) + .input(JsonValue.from(mapOf())) + .metadata(InsertProjectLogsEvent.Metadata.builder().model("model").build()) + .metrics( + InsertProjectLogsEvent.Metrics.builder() + .callerFilename(JsonValue.from(mapOf())) + .callerFunctionname(JsonValue.from(mapOf())) + .callerLineno(JsonValue.from(mapOf())) + .completionTokens(0L) + .end(0.0) + .promptTokens(0L) + .start(0.0) + .tokens(0L) + .build() + ) + .origin( + ObjectReference.builder() + .id("id") + ._xactId("_xact_id") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(ObjectReference.ObjectType.EXPERIMENT) + .created("created") + .build() + ) + .output(JsonValue.from(mapOf())) + .rootSpanId("root_span_id") + .scores( + InsertProjectLogsEvent.Scores.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .spanAttributes( + SpanAttributes.builder().name("name").type(SpanType.LLM).build() + ) + .spanId("span_id") + .addSpanParent("string") + .addTag("string") + .build() ) } @@ -208,20 +219,6 @@ internal class ProjectLogInsertParamsTest { val body = params._body() assertNotNull(body) - assertThat(body.events()).isEqualTo(listOf(InsertProjectLogsEvent.builder().build())) - } - - @Test - fun getPathParam() { - val params = - ProjectLogInsertParams.builder() - .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .addEvent(InsertProjectLogsEvent.builder().build()) - .build() - assertThat(params).isNotNull - // path param "projectId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(body.events()).containsExactly(InsertProjectLogsEvent.builder().build()) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogsEventTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogsEventTest.kt index ac983318..fdd0d545 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogsEventTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogsEventTest.kt @@ -4,6 +4,7 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import java.time.OffsetDateTime +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -120,7 +121,7 @@ internal class ProjectLogsEventTest { ) assertThat(projectLogsEvent.spanAttributes()) .contains(SpanAttributes.builder().name("name").type(SpanType.LLM).build()) - assertThat(projectLogsEvent.spanParents().get()).containsExactly("string") - assertThat(projectLogsEvent.tags().get()).containsExactly("string") + assertThat(projectLogsEvent.spanParents().getOrNull()).containsExactly("string") + assertThat(projectLogsEvent.tags().getOrNull()).containsExactly("string") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectRetrieveParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectRetrieveParamsTest.kt index ad7bf543..e83306b3 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectRetrieveParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectRetrieveParamsTest.kt @@ -13,15 +13,14 @@ internal class ProjectRetrieveParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = ProjectRetrieveParams.builder() .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - assertThat(params).isNotNull - // path param "projectId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreDeleteParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreDeleteParamsTest.kt index 3ba5951f..c90b6173 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreDeleteParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreDeleteParamsTest.kt @@ -15,15 +15,14 @@ internal class ProjectScoreDeleteParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = ProjectScoreDeleteParams.builder() .projectScoreId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - assertThat(params).isNotNull - // path param "projectScoreId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreRetrieveParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreRetrieveParamsTest.kt index a6f2bd61..8bfde8f2 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreRetrieveParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreRetrieveParamsTest.kt @@ -15,15 +15,14 @@ internal class ProjectScoreRetrieveParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = ProjectScoreRetrieveParams.builder() .projectScoreId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - assertThat(params).isNotNull - // path param "projectScoreId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParamsTest.kt index 5c2a615d..fc675dff 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParamsTest.kt @@ -40,6 +40,18 @@ internal class ProjectScoreUpdateParamsTest { .build() } + @Test + fun pathParams() { + val params = + ProjectScoreUpdateParams.builder() + .projectScoreId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun body() { val params = @@ -117,17 +129,4 @@ internal class ProjectScoreUpdateParamsTest { assertNotNull(body) } - - @Test - fun getPathParam() { - val params = - ProjectScoreUpdateParams.builder() - .projectScoreId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - assertThat(params).isNotNull - // path param "projectScoreId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") - } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectSettingsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectSettingsTest.kt index 7a9c2f21..767603bb 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectSettingsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectSettingsTest.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -26,7 +27,7 @@ internal class ProjectSettingsTest { assertThat(projectSettings.baselineExperimentId()) .contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(projectSettings.comparisonKey()).contains("comparison_key") - assertThat(projectSettings.spanFieldOrder().get()) + assertThat(projectSettings.spanFieldOrder().getOrNull()) .containsExactly( ProjectSettings.SpanFieldOrder.builder() .columnId("column_id") diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagDeleteParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagDeleteParamsTest.kt index 7de39ed3..16087334 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagDeleteParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagDeleteParamsTest.kt @@ -15,15 +15,14 @@ internal class ProjectTagDeleteParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = ProjectTagDeleteParams.builder() .projectTagId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - assertThat(params).isNotNull - // path param "projectTagId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagRetrieveParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagRetrieveParamsTest.kt index bceb5438..f7bbf553 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagRetrieveParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagRetrieveParamsTest.kt @@ -15,15 +15,14 @@ internal class ProjectTagRetrieveParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = ProjectTagRetrieveParams.builder() .projectTagId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - assertThat(params).isNotNull - // path param "projectTagId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParamsTest.kt index 0bda9b77..a66f060e 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParamsTest.kt @@ -18,6 +18,18 @@ internal class ProjectTagUpdateParamsTest { .build() } + @Test + fun pathParams() { + val params = + ProjectTagUpdateParams.builder() + .projectTagId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun body() { val params = @@ -47,17 +59,4 @@ internal class ProjectTagUpdateParamsTest { assertNotNull(body) } - - @Test - fun getPathParam() { - val params = - ProjectTagUpdateParams.builder() - .projectTagId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - assertThat(params).isNotNull - // path param "projectTagId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") - } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectUpdateParamsTest.kt index 231a5855..17f26452 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectUpdateParamsTest.kt @@ -30,6 +30,16 @@ internal class ProjectUpdateParamsTest { .build() } + @Test + fun pathParams() { + val params = + ProjectUpdateParams.builder().projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun body() { val params = @@ -82,15 +92,4 @@ internal class ProjectUpdateParamsTest { assertNotNull(body) } - - @Test - fun getPathParam() { - val params = - ProjectUpdateParams.builder().projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - assertThat(params).isNotNull - // path param "projectId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") - } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptCreateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptCreateParamsTest.kt index 4b481b7f..357be90b 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptCreateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptCreateParamsTest.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import kotlin.jvm.optionals.getOrNull import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -280,7 +281,7 @@ internal class PromptCreateParamsTest { ) .build() ) - assertThat(body.tags()).contains(listOf("string")) + assertThat(body.tags().getOrNull()).containsExactly("string") } @Test diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptDataTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptDataTest.kt index 88789045..f0acad00 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptDataTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptDataTest.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -155,7 +156,7 @@ internal class PromptDataTest { .build() ) ) - assertThat(promptData.toolFunctions().get()) + assertThat(promptData.toolFunctions().getOrNull()) .containsExactly( PromptData.ToolFunction.ofFunction( PromptData.ToolFunction.Function.builder() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptDeleteParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptDeleteParamsTest.kt index 5fa9d727..45b20f34 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptDeleteParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptDeleteParamsTest.kt @@ -13,13 +13,12 @@ internal class PromptDeleteParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = PromptDeleteParams.builder().promptId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - assertThat(params).isNotNull - // path param "promptId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptReplaceParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptReplaceParamsTest.kt index a3b083cf..2d6a3afe 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptReplaceParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptReplaceParamsTest.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import kotlin.jvm.optionals.getOrNull import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -280,7 +281,7 @@ internal class PromptReplaceParamsTest { ) .build() ) - assertThat(body.tags()).contains(listOf("string")) + assertThat(body.tags().getOrNull()).containsExactly("string") } @Test diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptRetrieveParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptRetrieveParamsTest.kt index a5915832..97f8cb26 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptRetrieveParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptRetrieveParamsTest.kt @@ -13,13 +13,12 @@ internal class PromptRetrieveParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = PromptRetrieveParams.builder().promptId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - assertThat(params).isNotNull - // path param "promptId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptTest.kt index 15360d72..396bf20e 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptTest.kt @@ -4,6 +4,7 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import java.time.OffsetDateTime +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -207,6 +208,6 @@ internal class PromptTest { ) .build() ) - assertThat(prompt.tags().get()).containsExactly("string") + assertThat(prompt.tags().getOrNull()).containsExactly("string") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptUpdateParamsTest.kt index 70bfe5a7..fe47a21d 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptUpdateParamsTest.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import kotlin.jvm.optionals.getOrNull import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -99,6 +100,16 @@ internal class PromptUpdateParamsTest { .build() } + @Test + fun pathParams() { + val params = + PromptUpdateParams.builder().promptId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun body() { val params = @@ -276,7 +287,7 @@ internal class PromptUpdateParamsTest { .build() ) assertThat(body.slug()).contains("slug") - assertThat(body.tags()).contains(listOf("string")) + assertThat(body.tags().getOrNull()).containsExactly("string") } @Test @@ -288,15 +299,4 @@ internal class PromptUpdateParamsTest { assertNotNull(body) } - - @Test - fun getPathParam() { - val params = - PromptUpdateParams.builder().promptId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - assertThat(params).isNotNull - // path param "promptId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") - } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleCreateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleCreateParamsTest.kt index 9310f639..a88e6617 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleCreateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleCreateParamsTest.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import kotlin.jvm.optionals.getOrNull import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -45,16 +46,15 @@ internal class RoleCreateParamsTest { assertNotNull(body) assertThat(body.name()).isEqualTo("x") assertThat(body.description()).contains("description") - assertThat(body.memberPermissions()) - .contains( - listOf( - RoleCreateParams.MemberPermission.builder() - .permission(Permission.CREATE) - .restrictObjectType(AclObjectType.ORGANIZATION) - .build() - ) + assertThat(body.memberPermissions().getOrNull()) + .containsExactly( + RoleCreateParams.MemberPermission.builder() + .permission(Permission.CREATE) + .restrictObjectType(AclObjectType.ORGANIZATION) + .build() ) - assertThat(body.memberRoles()).contains(listOf("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")) + assertThat(body.memberRoles().getOrNull()) + .containsExactly("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.orgName()).contains("org_name") } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleDeleteParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleDeleteParamsTest.kt index 6552fe89..8a61140e 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleDeleteParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleDeleteParamsTest.kt @@ -13,13 +13,12 @@ internal class RoleDeleteParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = RoleDeleteParams.builder().roleId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - assertThat(params).isNotNull - // path param "roleId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleReplaceParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleReplaceParamsTest.kt index d278709c..08ea1f4b 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleReplaceParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleReplaceParamsTest.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import kotlin.jvm.optionals.getOrNull import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -45,16 +46,15 @@ internal class RoleReplaceParamsTest { assertNotNull(body) assertThat(body.name()).isEqualTo("x") assertThat(body.description()).contains("description") - assertThat(body.memberPermissions()) - .contains( - listOf( - RoleReplaceParams.MemberPermission.builder() - .permission(Permission.CREATE) - .restrictObjectType(AclObjectType.ORGANIZATION) - .build() - ) + assertThat(body.memberPermissions().getOrNull()) + .containsExactly( + RoleReplaceParams.MemberPermission.builder() + .permission(Permission.CREATE) + .restrictObjectType(AclObjectType.ORGANIZATION) + .build() ) - assertThat(body.memberRoles()).contains(listOf("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")) + assertThat(body.memberRoles().getOrNull()) + .containsExactly("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.orgName()).contains("org_name") } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleRetrieveParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleRetrieveParamsTest.kt index 72b41378..27d753fa 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleRetrieveParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleRetrieveParamsTest.kt @@ -13,13 +13,12 @@ internal class RoleRetrieveParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = RoleRetrieveParams.builder().roleId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - assertThat(params).isNotNull - // path param "roleId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleTest.kt index c3adf0e4..bdfd04ed 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleTest.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.models import java.time.OffsetDateTime +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -33,14 +34,15 @@ internal class RoleTest { assertThat(role.created()).contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) assertThat(role.deletedAt()).contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) assertThat(role.description()).contains("description") - assertThat(role.memberPermissions().get()) + assertThat(role.memberPermissions().getOrNull()) .containsExactly( Role.MemberPermission.builder() .permission(Permission.CREATE) .restrictObjectType(AclObjectType.ORGANIZATION) .build() ) - assertThat(role.memberRoles().get()).containsExactly("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + assertThat(role.memberRoles().getOrNull()) + .containsExactly("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(role.orgId()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(role.userId()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleUpdateParamsTest.kt index 5108aba7..aa80e9be 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleUpdateParamsTest.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import kotlin.jvm.optionals.getOrNull import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -31,6 +32,16 @@ internal class RoleUpdateParamsTest { .build() } + @Test + fun pathParams() { + val params = + RoleUpdateParams.builder().roleId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun body() { val params = @@ -57,29 +68,26 @@ internal class RoleUpdateParamsTest { val body = params._body() assertNotNull(body) - assertThat(body.addMemberPermissions()) - .contains( - listOf( - RoleUpdateParams.AddMemberPermission.builder() - .permission(Permission.CREATE) - .restrictObjectType(AclObjectType.ORGANIZATION) - .build() - ) + assertThat(body.addMemberPermissions().getOrNull()) + .containsExactly( + RoleUpdateParams.AddMemberPermission.builder() + .permission(Permission.CREATE) + .restrictObjectType(AclObjectType.ORGANIZATION) + .build() ) - assertThat(body.addMemberRoles()).contains(listOf("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")) + assertThat(body.addMemberRoles().getOrNull()) + .containsExactly("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.description()).contains("description") assertThat(body.name()).contains("x") - assertThat(body.removeMemberPermissions()) - .contains( - listOf( - RoleUpdateParams.RemoveMemberPermission.builder() - .permission(Permission.CREATE) - .restrictObjectType(AclObjectType.ORGANIZATION) - .build() - ) + assertThat(body.removeMemberPermissions().getOrNull()) + .containsExactly( + RoleUpdateParams.RemoveMemberPermission.builder() + .permission(Permission.CREATE) + .restrictObjectType(AclObjectType.ORGANIZATION) + .build() ) - assertThat(body.removeMemberRoles()) - .contains(listOf("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")) + assertThat(body.removeMemberRoles().getOrNull()) + .containsExactly("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") } @Test @@ -91,15 +99,4 @@ internal class RoleUpdateParamsTest { assertNotNull(body) } - - @Test - fun getPathParam() { - val params = - RoleUpdateParams.builder().roleId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - assertThat(params).isNotNull - // path param "roleId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") - } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeDeleteParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeDeleteParamsTest.kt index a2f0c37f..09ce2983 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeDeleteParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeDeleteParamsTest.kt @@ -15,15 +15,14 @@ internal class SpanIframeDeleteParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = SpanIframeDeleteParams.builder() .spanIframeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - assertThat(params).isNotNull - // path param "spanIframeId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeRetrieveParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeRetrieveParamsTest.kt index adab9365..885d2d46 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeRetrieveParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeRetrieveParamsTest.kt @@ -15,15 +15,14 @@ internal class SpanIframeRetrieveParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = SpanIframeRetrieveParams.builder() .spanIframeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - assertThat(params).isNotNull - // path param "spanIframeId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParamsTest.kt index fd52b975..fdf02719 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParamsTest.kt @@ -19,6 +19,18 @@ internal class SpanIframeUpdateParamsTest { .build() } + @Test + fun pathParams() { + val params = + SpanIframeUpdateParams.builder() + .spanIframeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun body() { val params = @@ -50,17 +62,4 @@ internal class SpanIframeUpdateParamsTest { assertNotNull(body) } - - @Test - fun getPathParam() { - val params = - SpanIframeUpdateParams.builder() - .spanIframeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - assertThat(params).isNotNull - // path param "spanIframeId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") - } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/UserRetrieveParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/UserRetrieveParamsTest.kt index 6c4f828f..f684fdad 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/UserRetrieveParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/UserRetrieveParamsTest.kt @@ -13,13 +13,12 @@ internal class UserRetrieveParamsTest { } @Test - fun getPathParam() { + fun pathParams() { val params = UserRetrieveParams.builder().userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - assertThat(params).isNotNull - // path param "userId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") + assertThat(params._pathParam(1)).isEqualTo("") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDataSearchTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDataSearchTest.kt index bd1ce88f..959020e8 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDataSearchTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDataSearchTest.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -18,12 +19,13 @@ internal class ViewDataSearchTest { .addTag(JsonValue.from(mapOf())) .build() assertThat(viewDataSearch).isNotNull - assertThat(viewDataSearch.filter().get()) + assertThat(viewDataSearch.filter().getOrNull()) .containsExactly(JsonValue.from(mapOf())) - assertThat(viewDataSearch.match().get()) + assertThat(viewDataSearch.match().getOrNull()) .containsExactly(JsonValue.from(mapOf())) - assertThat(viewDataSearch.sort().get()) + assertThat(viewDataSearch.sort().getOrNull()) + .containsExactly(JsonValue.from(mapOf())) + assertThat(viewDataSearch.tag().getOrNull()) .containsExactly(JsonValue.from(mapOf())) - assertThat(viewDataSearch.tag().get()).containsExactly(JsonValue.from(mapOf())) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDeleteParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDeleteParamsTest.kt index 6d6c784c..6248015c 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDeleteParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDeleteParamsTest.kt @@ -18,7 +18,7 @@ internal class ViewDeleteParamsTest { } @Test - fun body() { + fun pathParams() { val params = ViewDeleteParams.builder() .viewId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -26,15 +26,13 @@ internal class ViewDeleteParamsTest { .objectType(AclObjectType.ORGANIZATION) .build() - val body = params._body() - - assertNotNull(body) - assertThat(body.objectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - assertThat(body.objectType()).isEqualTo(AclObjectType.ORGANIZATION) + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") } @Test - fun bodyWithoutOptionalFields() { + fun body() { val params = ViewDeleteParams.builder() .viewId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -48,19 +46,4 @@ internal class ViewDeleteParamsTest { assertThat(body.objectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.objectType()).isEqualTo(AclObjectType.ORGANIZATION) } - - @Test - fun getPathParam() { - val params = - ViewDeleteParams.builder() - .viewId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .objectType(AclObjectType.ORGANIZATION) - .build() - assertThat(params).isNotNull - // path param "viewId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") - } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewOptionsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewOptionsTest.kt index 1c0aceec..59d5b6b7 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewOptionsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewOptionsTest.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -28,7 +29,7 @@ internal class ViewOptionsTest { .rowHeight("rowHeight") .build() assertThat(viewOptions).isNotNull - assertThat(viewOptions.columnOrder().get()).containsExactly("string") + assertThat(viewOptions.columnOrder().getOrNull()).containsExactly("string") assertThat(viewOptions.columnSizing()) .contains( ViewOptions.ColumnSizing.builder() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewRetrieveParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewRetrieveParamsTest.kt index d73a583b..84cc78de 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewRetrieveParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewRetrieveParamsTest.kt @@ -18,7 +18,7 @@ internal class ViewRetrieveParamsTest { } @Test - fun queryParams() { + fun pathParams() { val params = ViewRetrieveParams.builder() .viewId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -26,19 +26,13 @@ internal class ViewRetrieveParamsTest { .objectType(AclObjectType.ORGANIZATION) .build() - val queryParams = params._queryParams() - - assertThat(queryParams) - .isEqualTo( - QueryParams.builder() - .put("object_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .put("object_type", "organization") - .build() - ) + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") } @Test - fun queryParamsWithoutOptionalFields() { + fun queryParams() { val params = ViewRetrieveParams.builder() .viewId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -56,19 +50,4 @@ internal class ViewRetrieveParamsTest { .build() ) } - - @Test - fun getPathParam() { - val params = - ViewRetrieveParams.builder() - .viewId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .objectType(AclObjectType.ORGANIZATION) - .build() - assertThat(params).isNotNull - // path param "viewId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") - } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewUpdateParamsTest.kt index 36044079..67aaa298 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewUpdateParamsTest.kt @@ -51,6 +51,20 @@ internal class ViewUpdateParamsTest { .build() } + @Test + fun pathParams() { + val params = + ViewUpdateParams.builder() + .viewId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(AclObjectType.ORGANIZATION) + .build() + + assertThat(params._pathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + @Test fun body() { val params = @@ -150,19 +164,4 @@ internal class ViewUpdateParamsTest { assertThat(body.objectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.objectType()).isEqualTo(AclObjectType.ORGANIZATION) } - - @Test - fun getPathParam() { - val params = - ViewUpdateParams.builder() - .viewId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .objectType(AclObjectType.ORGANIZATION) - .build() - assertThat(params).isNotNull - // path param "viewId" - assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - // out-of-bound path param - assertThat(params.getPathParam(1)).isEqualTo("") - } } From e7cdefcd06a55332f6e7ef6a6b729f33207a7834 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 19 Mar 2025 13:01:33 +0000 Subject: [PATCH 03/42] chore(internal): reformat some tests (#160) chore(internal): generate more tests --- .../com/braintrustdata/api/models/AISecretTest.kt | 4 ++-- .../api/models/AclBatchUpdateResponseTest.kt | 4 ++-- .../kotlin/com/braintrustdata/api/models/AclTest.kt | 4 ++-- .../com/braintrustdata/api/models/ApiKeyTest.kt | 4 ++-- .../models/ChatCompletionContentPartImageTest.kt | 4 ++-- .../api/models/ChatCompletionContentPartTextTest.kt | 4 ++-- .../api/models/ChatCompletionMessageToolCallTest.kt | 4 ++-- .../com/braintrustdata/api/models/CodeBundleTest.kt | 4 ++-- .../api/models/CreateApiKeyOutputTest.kt | 4 ++-- .../api/models/CrossObjectInsertResponseTest.kt | 4 ++-- .../braintrustdata/api/models/DataSummaryTest.kt | 4 ++-- .../braintrustdata/api/models/DatasetEventTest.kt | 4 ++-- .../com/braintrustdata/api/models/DatasetTest.kt | 4 ++-- .../api/models/EnvVarListResponseTest.kt | 4 ++-- .../com/braintrustdata/api/models/EnvVarTest.kt | 4 ++-- .../api/models/ExperimentEventTest.kt | 4 ++-- .../com/braintrustdata/api/models/ExperimentTest.kt | 4 ++-- .../api/models/FeedbackDatasetItemTest.kt | 4 ++-- .../api/models/FeedbackExperimentItemTest.kt | 4 ++-- .../api/models/FeedbackProjectLogsItemTest.kt | 4 ++-- .../api/models/FeedbackResponseSchemaTest.kt | 4 ++-- .../api/models/FetchDatasetEventsResponseTest.kt | 4 ++-- .../api/models/FetchExperimentEventsResponseTest.kt | 4 ++-- .../models/FetchProjectLogsEventsResponseTest.kt | 4 ++-- .../api/models/FunctionInvokeResponseTest.kt | 13 +++++++++++++ .../com/braintrustdata/api/models/FunctionTest.kt | 4 ++-- .../com/braintrustdata/api/models/GroupTest.kt | 4 ++-- .../api/models/InsertDatasetEventTest.kt | 4 ++-- .../api/models/InsertEventsResponseTest.kt | 4 ++-- .../api/models/InsertExperimentEventTest.kt | 4 ++-- .../api/models/InsertProjectLogsEventTest.kt | 4 ++-- .../braintrustdata/api/models/MetricSummaryTest.kt | 4 ++-- .../api/models/ObjectReferenceTest.kt | 4 ++-- .../api/models/OnlineScoreConfigTest.kt | 4 ++-- .../braintrustdata/api/models/OrganizationTest.kt | 4 ++-- .../models/PatchOrganizationMembersOutputTest.kt | 4 ++-- .../api/models/ProjectLogsEventTest.kt | 4 ++-- .../api/models/ProjectScoreCategoryTest.kt | 4 ++-- .../api/models/ProjectScoreConfigTest.kt | 4 ++-- .../braintrustdata/api/models/ProjectScoreTest.kt | 4 ++-- .../api/models/ProjectSettingsTest.kt | 4 ++-- .../com/braintrustdata/api/models/ProjectTagTest.kt | 4 ++-- .../com/braintrustdata/api/models/ProjectTest.kt | 4 ++-- .../com/braintrustdata/api/models/PromptDataTest.kt | 4 ++-- .../braintrustdata/api/models/PromptOptionsTest.kt | 4 ++-- .../com/braintrustdata/api/models/PromptTest.kt | 4 ++-- .../com/braintrustdata/api/models/RepoInfoTest.kt | 4 ++-- .../com/braintrustdata/api/models/RoleTest.kt | 4 ++-- .../braintrustdata/api/models/ScoreSummaryTest.kt | 4 ++-- .../braintrustdata/api/models/SpanAttributesTest.kt | 4 ++-- .../com/braintrustdata/api/models/SpanIFrameTest.kt | 4 ++-- .../api/models/SummarizeDatasetResponseTest.kt | 4 ++-- .../api/models/SummarizeExperimentResponseTest.kt | 4 ++-- .../com/braintrustdata/api/models/UserTest.kt | 4 ++-- .../braintrustdata/api/models/ViewDataSearchTest.kt | 4 ++-- .../com/braintrustdata/api/models/ViewDataTest.kt | 4 ++-- .../braintrustdata/api/models/ViewOptionsTest.kt | 4 ++-- .../com/braintrustdata/api/models/ViewTest.kt | 4 ++-- 58 files changed, 127 insertions(+), 114 deletions(-) create mode 100644 braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionInvokeResponseTest.kt diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AISecretTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AISecretTest.kt index d7241b89..28b81361 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AISecretTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AISecretTest.kt @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test internal class AISecretTest { @Test - fun createAISecret() { + fun create() { val aiSecret = AISecret.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -26,7 +26,7 @@ internal class AISecretTest { .type("type") .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() - assertThat(aiSecret).isNotNull + assertThat(aiSecret.id()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(aiSecret.name()).isEqualTo("name") assertThat(aiSecret.orgId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclBatchUpdateResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclBatchUpdateResponseTest.kt index b04bfa85..4b3ec7dd 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclBatchUpdateResponseTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclBatchUpdateResponseTest.kt @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test internal class AclBatchUpdateResponseTest { @Test - fun createAclBatchUpdateResponse() { + fun create() { val aclBatchUpdateResponse = AclBatchUpdateResponse.builder() .addAddedAcl( @@ -41,7 +41,7 @@ internal class AclBatchUpdateResponseTest { .build() ) .build() - assertThat(aclBatchUpdateResponse).isNotNull + assertThat(aclBatchUpdateResponse.addedAcls()) .containsExactly( Acl.builder() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclTest.kt index 39258080..a29f2f9d 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclTest.kt @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test internal class AclTest { @Test - fun createAcl() { + fun create() { val acl = Acl.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -23,7 +23,7 @@ internal class AclTest { .roleId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - assertThat(acl).isNotNull + assertThat(acl.id()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(acl._objectOrgId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(acl.objectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ApiKeyTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ApiKeyTest.kt index 099b0e65..bc43594f 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ApiKeyTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ApiKeyTest.kt @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test internal class ApiKeyTest { @Test - fun createApiKey() { + fun create() { val apiKey = ApiKey.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -19,7 +19,7 @@ internal class ApiKeyTest { .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - assertThat(apiKey).isNotNull + assertThat(apiKey.id()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(apiKey.name()).isEqualTo("name") assertThat(apiKey.previewName()).isEqualTo("preview_name") diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImageTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImageTest.kt index b826be89..57b5da08 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImageTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImageTest.kt @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test internal class ChatCompletionContentPartImageTest { @Test - fun createChatCompletionContentPartImage() { + fun create() { val chatCompletionContentPartImage = ChatCompletionContentPartImage.builder() .imageUrl( @@ -19,7 +19,7 @@ internal class ChatCompletionContentPartImageTest { ) .type(ChatCompletionContentPartImage.Type.IMAGE_URL) .build() - assertThat(chatCompletionContentPartImage).isNotNull + assertThat(chatCompletionContentPartImage.imageUrl()) .isEqualTo( ChatCompletionContentPartImage.ImageUrl.builder() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartTextTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartTextTest.kt index 2e8d9c23..5c43426a 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartTextTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartTextTest.kt @@ -8,13 +8,13 @@ import org.junit.jupiter.api.Test internal class ChatCompletionContentPartTextTest { @Test - fun createChatCompletionContentPartText() { + fun create() { val chatCompletionContentPartText = ChatCompletionContentPartText.builder() .type(ChatCompletionContentPartText.Type.TEXT) .text("text") .build() - assertThat(chatCompletionContentPartText).isNotNull + assertThat(chatCompletionContentPartText.type()) .isEqualTo(ChatCompletionContentPartText.Type.TEXT) assertThat(chatCompletionContentPartText.text()).contains("text") diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ChatCompletionMessageToolCallTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ChatCompletionMessageToolCallTest.kt index b140cc39..9c78253b 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ChatCompletionMessageToolCallTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ChatCompletionMessageToolCallTest.kt @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test internal class ChatCompletionMessageToolCallTest { @Test - fun createChatCompletionMessageToolCall() { + fun create() { val chatCompletionMessageToolCall = ChatCompletionMessageToolCall.builder() .id("id") @@ -20,7 +20,7 @@ internal class ChatCompletionMessageToolCallTest { ) .type(ChatCompletionMessageToolCall.Type.FUNCTION) .build() - assertThat(chatCompletionMessageToolCall).isNotNull + assertThat(chatCompletionMessageToolCall.id()).isEqualTo("id") assertThat(chatCompletionMessageToolCall.function()) .isEqualTo( diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/CodeBundleTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/CodeBundleTest.kt index 5eb775e3..b24d1bc6 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/CodeBundleTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/CodeBundleTest.kt @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test internal class CodeBundleTest { @Test - fun createCodeBundle() { + fun create() { val codeBundle = CodeBundle.builder() .bundleId("bundle_id") @@ -31,7 +31,7 @@ internal class CodeBundleTest { ) .preview("preview") .build() - assertThat(codeBundle).isNotNull + assertThat(codeBundle.bundleId()).isEqualTo("bundle_id") assertThat(codeBundle.location()) .isEqualTo( diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/CreateApiKeyOutputTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/CreateApiKeyOutputTest.kt index f9057687..f75c2d79 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/CreateApiKeyOutputTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/CreateApiKeyOutputTest.kt @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test internal class CreateApiKeyOutputTest { @Test - fun createCreateApiKeyOutput() { + fun create() { val createApiKeyOutput = CreateApiKeyOutput.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -20,7 +20,7 @@ internal class CreateApiKeyOutputTest { .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - assertThat(createApiKeyOutput).isNotNull + assertThat(createApiKeyOutput.id()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(createApiKeyOutput.key()).isEqualTo("key") assertThat(createApiKeyOutput.name()).isEqualTo("name") diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponseTest.kt index 4abcfb9d..22dfda4d 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponseTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponseTest.kt @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test internal class CrossObjectInsertResponseTest { @Test - fun createCrossObjectInsertResponse() { + fun create() { val crossObjectInsertResponse = CrossObjectInsertResponse.builder() .dataset( @@ -37,7 +37,7 @@ internal class CrossObjectInsertResponseTest { .build() ) .build() - assertThat(crossObjectInsertResponse).isNotNull + assertThat(crossObjectInsertResponse.dataset()) .contains( CrossObjectInsertResponse.Dataset.builder() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DataSummaryTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DataSummaryTest.kt index f7759625..c7d0aae7 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DataSummaryTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DataSummaryTest.kt @@ -8,9 +8,9 @@ import org.junit.jupiter.api.Test internal class DataSummaryTest { @Test - fun createDataSummary() { + fun create() { val dataSummary = DataSummary.builder().totalRecords(0L).build() - assertThat(dataSummary).isNotNull + assertThat(dataSummary.totalRecords()).isEqualTo(0L) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetEventTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetEventTest.kt index 3616a5c2..187ec07a 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetEventTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetEventTest.kt @@ -11,7 +11,7 @@ import org.junit.jupiter.api.Test internal class DatasetEventTest { @Test - fun createDatasetEvent() { + fun create() { val datasetEvent = DatasetEvent.builder() .id("id") @@ -36,7 +36,7 @@ internal class DatasetEventTest { ) .addTag("string") .build() - assertThat(datasetEvent).isNotNull + assertThat(datasetEvent.id()).isEqualTo("id") assertThat(datasetEvent._xactId()).isEqualTo("_xact_id") assertThat(datasetEvent.created()) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetTest.kt index 5751efca..7fd17940 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetTest.kt @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test internal class DatasetTest { @Test - fun createDataset() { + fun create() { val dataset = Dataset.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -26,7 +26,7 @@ internal class DatasetTest { ) .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - assertThat(dataset).isNotNull + assertThat(dataset.id()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(dataset.name()).isEqualTo("name") assertThat(dataset.projectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarListResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarListResponseTest.kt index 801245e2..7ffd32f0 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarListResponseTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarListResponseTest.kt @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test internal class EnvVarListResponseTest { @Test - fun createEnvVarListResponse() { + fun create() { val envVarListResponse = EnvVarListResponse.builder() .addObject( @@ -23,7 +23,7 @@ internal class EnvVarListResponseTest { .build() ) .build() - assertThat(envVarListResponse).isNotNull + assertThat(envVarListResponse.objects()) .containsExactly( EnvVar.builder() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarTest.kt index 6df9126a..f1fa4e2d 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarTest.kt @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test internal class EnvVarTest { @Test - fun createEnvVar() { + fun create() { val envVar = EnvVar.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -19,7 +19,7 @@ internal class EnvVarTest { .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .used(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() - assertThat(envVar).isNotNull + assertThat(envVar.id()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(envVar.name()).isEqualTo("name") assertThat(envVar.objectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentEventTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentEventTest.kt index 09e01ad6..d260c428 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentEventTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentEventTest.kt @@ -11,7 +11,7 @@ import org.junit.jupiter.api.Test internal class ExperimentEventTest { @Test - fun createExperimentEvent() { + fun create() { val experimentEvent = ExperimentEvent.builder() .id("id") @@ -64,7 +64,7 @@ internal class ExperimentEventTest { .addSpanParent("string") .addTag("string") .build() - assertThat(experimentEvent).isNotNull + assertThat(experimentEvent.id()).isEqualTo("id") assertThat(experimentEvent._xactId()).isEqualTo("_xact_id") assertThat(experimentEvent.created()) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentTest.kt index 534b2774..3d087ff0 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentTest.kt @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test internal class ExperimentTest { @Test - fun createExperiment() { + fun create() { val experiment = Experiment.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -44,7 +44,7 @@ internal class ExperimentTest { ) .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - assertThat(experiment).isNotNull + assertThat(experiment.id()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(experiment.name()).isEqualTo("name") assertThat(experiment.projectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackDatasetItemTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackDatasetItemTest.kt index 52cac9b6..0c0f462c 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackDatasetItemTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackDatasetItemTest.kt @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test internal class FeedbackDatasetItemTest { @Test - fun createFeedbackDatasetItem() { + fun create() { val feedbackDatasetItem = FeedbackDatasetItem.builder() .id("id") @@ -23,7 +23,7 @@ internal class FeedbackDatasetItemTest { .source(FeedbackDatasetItem.Source.APP) .addTag("string") .build() - assertThat(feedbackDatasetItem).isNotNull + assertThat(feedbackDatasetItem.id()).isEqualTo("id") assertThat(feedbackDatasetItem.comment()).contains("comment") assertThat(feedbackDatasetItem.metadata()) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackExperimentItemTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackExperimentItemTest.kt index cfbe1bbe..d776a43a 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackExperimentItemTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackExperimentItemTest.kt @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test internal class FeedbackExperimentItemTest { @Test - fun createFeedbackExperimentItem() { + fun create() { val feedbackExperimentItem = FeedbackExperimentItem.builder() .id("id") @@ -29,7 +29,7 @@ internal class FeedbackExperimentItemTest { .source(FeedbackExperimentItem.Source.APP) .addTag("string") .build() - assertThat(feedbackExperimentItem).isNotNull + assertThat(feedbackExperimentItem.id()).isEqualTo("id") assertThat(feedbackExperimentItem.comment()).contains("comment") assertThat(feedbackExperimentItem._expected()) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItemTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItemTest.kt index 91358ac0..7ff09552 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItemTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItemTest.kt @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test internal class FeedbackProjectLogsItemTest { @Test - fun createFeedbackProjectLogsItem() { + fun create() { val feedbackProjectLogsItem = FeedbackProjectLogsItem.builder() .id("id") @@ -29,7 +29,7 @@ internal class FeedbackProjectLogsItemTest { .source(FeedbackProjectLogsItem.Source.APP) .addTag("string") .build() - assertThat(feedbackProjectLogsItem).isNotNull + assertThat(feedbackProjectLogsItem.id()).isEqualTo("id") assertThat(feedbackProjectLogsItem.comment()).contains("comment") assertThat(feedbackProjectLogsItem._expected()) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackResponseSchemaTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackResponseSchemaTest.kt index bafdb30c..6ddb8c4f 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackResponseSchemaTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackResponseSchemaTest.kt @@ -8,10 +8,10 @@ import org.junit.jupiter.api.Test internal class FeedbackResponseSchemaTest { @Test - fun createFeedbackResponseSchema() { + fun create() { val feedbackResponseSchema = FeedbackResponseSchema.builder().status(FeedbackResponseSchema.Status.SUCCESS).build() - assertThat(feedbackResponseSchema).isNotNull + assertThat(feedbackResponseSchema.status()).isEqualTo(FeedbackResponseSchema.Status.SUCCESS) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FetchDatasetEventsResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FetchDatasetEventsResponseTest.kt index ced9effd..aeffd433 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FetchDatasetEventsResponseTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FetchDatasetEventsResponseTest.kt @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test internal class FetchDatasetEventsResponseTest { @Test - fun createFetchDatasetEventsResponse() { + fun create() { val fetchDatasetEventsResponse = FetchDatasetEventsResponse.builder() .addEvent( @@ -40,7 +40,7 @@ internal class FetchDatasetEventsResponseTest { ) .cursor("cursor") .build() - assertThat(fetchDatasetEventsResponse).isNotNull + assertThat(fetchDatasetEventsResponse.events()) .containsExactly( DatasetEvent.builder() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FetchExperimentEventsResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FetchExperimentEventsResponseTest.kt index 7ec8e63b..4d25b839 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FetchExperimentEventsResponseTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FetchExperimentEventsResponseTest.kt @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test internal class FetchExperimentEventsResponseTest { @Test - fun createFetchExperimentEventsResponse() { + fun create() { val fetchExperimentEventsResponse = FetchExperimentEventsResponse.builder() .addEvent( @@ -70,7 +70,7 @@ internal class FetchExperimentEventsResponseTest { ) .cursor("cursor") .build() - assertThat(fetchExperimentEventsResponse).isNotNull + assertThat(fetchExperimentEventsResponse.events()) .containsExactly( ExperimentEvent.builder() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FetchProjectLogsEventsResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FetchProjectLogsEventsResponseTest.kt index ae7b0b5a..600d5ecc 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FetchProjectLogsEventsResponseTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FetchProjectLogsEventsResponseTest.kt @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test internal class FetchProjectLogsEventsResponseTest { @Test - fun createFetchProjectLogsEventsResponse() { + fun create() { val fetchProjectLogsEventsResponse = FetchProjectLogsEventsResponse.builder() .addEvent( @@ -71,7 +71,7 @@ internal class FetchProjectLogsEventsResponseTest { ) .cursor("cursor") .build() - assertThat(fetchProjectLogsEventsResponse).isNotNull + assertThat(fetchProjectLogsEventsResponse.events()) .containsExactly( ProjectLogsEvent.builder() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionInvokeResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionInvokeResponseTest.kt new file mode 100644 index 00000000..9dd15f08 --- /dev/null +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionInvokeResponseTest.kt @@ -0,0 +1,13 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import org.junit.jupiter.api.Test + +internal class FunctionInvokeResponseTest { + + @Test + fun create() { + val functionInvokeResponse = FunctionInvokeResponse.builder().build() + } +} diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionTest.kt index cf3ad0e4..a19daa0b 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionTest.kt @@ -11,7 +11,7 @@ import org.junit.jupiter.api.Test internal class FunctionTest { @Test - fun createFunction() { + fun create() { val function = Function.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -129,7 +129,7 @@ internal class FunctionTest { ) .addTag("string") .build() - assertThat(function).isNotNull + assertThat(function.id()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(function._xactId()).isEqualTo("_xact_id") assertThat(function.functionData()) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupTest.kt index 360283d5..d2909368 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupTest.kt @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test internal class GroupTest { @Test - fun createGroup() { + fun create() { val group = Group.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -23,7 +23,7 @@ internal class GroupTest { .addMemberUser("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - assertThat(group).isNotNull + assertThat(group.id()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(group.name()).isEqualTo("name") assertThat(group.orgId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertDatasetEventTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertDatasetEventTest.kt index 31c116a5..a1dd7541 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertDatasetEventTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertDatasetEventTest.kt @@ -11,7 +11,7 @@ import org.junit.jupiter.api.Test internal class InsertDatasetEventTest { @Test - fun createInsertDatasetEvent() { + fun create() { val insertDatasetEvent = InsertDatasetEvent.builder() .id("id") @@ -37,7 +37,7 @@ internal class InsertDatasetEventTest { .addSpanParent("string") .addTag("string") .build() - assertThat(insertDatasetEvent).isNotNull + assertThat(insertDatasetEvent.id()).contains("id") assertThat(insertDatasetEvent._isMerge()).contains(true) assertThat(insertDatasetEvent._mergePaths().getOrNull()).containsExactly(listOf("string")) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertEventsResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertEventsResponseTest.kt index bc8f0a96..538b7e72 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertEventsResponseTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertEventsResponseTest.kt @@ -8,9 +8,9 @@ import org.junit.jupiter.api.Test internal class InsertEventsResponseTest { @Test - fun createInsertEventsResponse() { + fun create() { val insertEventsResponse = InsertEventsResponse.builder().addRowId("string").build() - assertThat(insertEventsResponse).isNotNull + assertThat(insertEventsResponse.rowIds()).containsExactly("string") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertExperimentEventTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertExperimentEventTest.kt index 127c3e49..9f0a6ed9 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertExperimentEventTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertExperimentEventTest.kt @@ -11,7 +11,7 @@ import org.junit.jupiter.api.Test internal class InsertExperimentEventTest { @Test - fun createInsertExperimentEvent() { + fun create() { val insertExperimentEvent = InsertExperimentEvent.builder() .id("id") @@ -64,7 +64,7 @@ internal class InsertExperimentEventTest { .addSpanParent("string") .addTag("string") .build() - assertThat(insertExperimentEvent).isNotNull + assertThat(insertExperimentEvent.id()).contains("id") assertThat(insertExperimentEvent._isMerge()).contains(true) assertThat(insertExperimentEvent._mergePaths().getOrNull()) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertProjectLogsEventTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertProjectLogsEventTest.kt index 76faf6a0..76148f90 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertProjectLogsEventTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertProjectLogsEventTest.kt @@ -11,7 +11,7 @@ import org.junit.jupiter.api.Test internal class InsertProjectLogsEventTest { @Test - fun createInsertProjectLogsEvent() { + fun create() { val insertProjectLogsEvent = InsertProjectLogsEvent.builder() .id("id") @@ -64,7 +64,7 @@ internal class InsertProjectLogsEventTest { .addSpanParent("string") .addTag("string") .build() - assertThat(insertProjectLogsEvent).isNotNull + assertThat(insertProjectLogsEvent.id()).contains("id") assertThat(insertProjectLogsEvent._isMerge()).contains(true) assertThat(insertProjectLogsEvent._mergePaths().getOrNull()) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/MetricSummaryTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/MetricSummaryTest.kt index a1dc0294..c7c267e4 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/MetricSummaryTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/MetricSummaryTest.kt @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test internal class MetricSummaryTest { @Test - fun createMetricSummary() { + fun create() { val metricSummary = MetricSummary.builder() .improvements(0L) @@ -18,7 +18,7 @@ internal class MetricSummaryTest { .unit("unit") .diff(0.0) .build() - assertThat(metricSummary).isNotNull + assertThat(metricSummary.improvements()).isEqualTo(0L) assertThat(metricSummary.metric()).isEqualTo(0.0) assertThat(metricSummary.name()).isEqualTo("name") diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ObjectReferenceTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ObjectReferenceTest.kt index cd116d19..10bd75a5 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ObjectReferenceTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ObjectReferenceTest.kt @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test internal class ObjectReferenceTest { @Test - fun createObjectReference() { + fun create() { val objectReference = ObjectReference.builder() .id("id") @@ -17,7 +17,7 @@ internal class ObjectReferenceTest { .objectType(ObjectReference.ObjectType.EXPERIMENT) .created("created") .build() - assertThat(objectReference).isNotNull + assertThat(objectReference.id()).isEqualTo("id") assertThat(objectReference._xactId()).isEqualTo("_xact_id") assertThat(objectReference.objectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OnlineScoreConfigTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OnlineScoreConfigTest.kt index 5fe9bcbb..556b42d3 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OnlineScoreConfigTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OnlineScoreConfigTest.kt @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test internal class OnlineScoreConfigTest { @Test - fun createOnlineScoreConfig() { + fun create() { val onlineScoreConfig = OnlineScoreConfig.builder() .samplingRate(0.0) @@ -22,7 +22,7 @@ internal class OnlineScoreConfigTest { .applyToRootSpan(true) .addApplyToSpanName("string") .build() - assertThat(onlineScoreConfig).isNotNull + assertThat(onlineScoreConfig.samplingRate()).isEqualTo(0.0) assertThat(onlineScoreConfig.scorers()) .containsExactly( diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationTest.kt index d5220152..8e7ab68d 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationTest.kt @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test internal class OrganizationTest { @Test - fun createOrganization() { + fun create() { val organization = Organization.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -20,7 +20,7 @@ internal class OrganizationTest { .proxyUrl("proxy_url") .realtimeUrl("realtime_url") .build() - assertThat(organization).isNotNull + assertThat(organization.id()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(organization.name()).isEqualTo("name") assertThat(organization.apiUrl()).contains("api_url") diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PatchOrganizationMembersOutputTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PatchOrganizationMembersOutputTest.kt index 8a00b5e5..c25d8575 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PatchOrganizationMembersOutputTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PatchOrganizationMembersOutputTest.kt @@ -8,14 +8,14 @@ import org.junit.jupiter.api.Test internal class PatchOrganizationMembersOutputTest { @Test - fun createPatchOrganizationMembersOutput() { + fun create() { val patchOrganizationMembersOutput = PatchOrganizationMembersOutput.builder() .orgId("org_id") .status(PatchOrganizationMembersOutput.Status.SUCCESS) .sendEmailError("send_email_error") .build() - assertThat(patchOrganizationMembersOutput).isNotNull + assertThat(patchOrganizationMembersOutput.orgId()).isEqualTo("org_id") assertThat(patchOrganizationMembersOutput.status()) .isEqualTo(PatchOrganizationMembersOutput.Status.SUCCESS) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogsEventTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogsEventTest.kt index fdd0d545..48cfb3bc 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogsEventTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogsEventTest.kt @@ -11,7 +11,7 @@ import org.junit.jupiter.api.Test internal class ProjectLogsEventTest { @Test - fun createProjectLogsEvent() { + fun create() { val projectLogsEvent = ProjectLogsEvent.builder() .id("id") @@ -65,7 +65,7 @@ internal class ProjectLogsEventTest { .addSpanParent("string") .addTag("string") .build() - assertThat(projectLogsEvent).isNotNull + assertThat(projectLogsEvent.id()).isEqualTo("id") assertThat(projectLogsEvent._xactId()).isEqualTo("_xact_id") assertThat(projectLogsEvent.created()) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreCategoryTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreCategoryTest.kt index eb62ebe7..9368c64a 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreCategoryTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreCategoryTest.kt @@ -8,9 +8,9 @@ import org.junit.jupiter.api.Test internal class ProjectScoreCategoryTest { @Test - fun createProjectScoreCategory() { + fun create() { val projectScoreCategory = ProjectScoreCategory.builder().name("name").value(0.0).build() - assertThat(projectScoreCategory).isNotNull + assertThat(projectScoreCategory.name()).isEqualTo("name") assertThat(projectScoreCategory.value()).isEqualTo(0.0) } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreConfigTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreConfigTest.kt index 40346457..e3a1e013 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreConfigTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreConfigTest.kt @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test internal class ProjectScoreConfigTest { @Test - fun createProjectScoreConfig() { + fun create() { val projectScoreConfig = ProjectScoreConfig.builder() .destination("destination") @@ -27,7 +27,7 @@ internal class ProjectScoreConfigTest { .build() ) .build() - assertThat(projectScoreConfig).isNotNull + assertThat(projectScoreConfig.destination()).contains("destination") assertThat(projectScoreConfig.multiSelect()).contains(true) assertThat(projectScoreConfig.online()) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreTest.kt index 576f47a4..ffeec510 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreTest.kt @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test internal class ProjectScoreTest { @Test - fun createProjectScore() { + fun create() { val projectScore = ProjectScore.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -43,7 +43,7 @@ internal class ProjectScoreTest { .description("description") .position("position") .build() - assertThat(projectScore).isNotNull + assertThat(projectScore.id()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(projectScore.name()).isEqualTo("name") assertThat(projectScore.projectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectSettingsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectSettingsTest.kt index 767603bb..5cfa962c 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectSettingsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectSettingsTest.kt @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test internal class ProjectSettingsTest { @Test - fun createProjectSettings() { + fun create() { val projectSettings = ProjectSettings.builder() .baselineExperimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -23,7 +23,7 @@ internal class ProjectSettingsTest { .build() ) .build() - assertThat(projectSettings).isNotNull + assertThat(projectSettings.baselineExperimentId()) .contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(projectSettings.comparisonKey()).contains("comparison_key") diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagTest.kt index 23968bbb..80341d14 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagTest.kt @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test internal class ProjectTagTest { @Test - fun createProjectTag() { + fun create() { val projectTag = ProjectTag.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -20,7 +20,7 @@ internal class ProjectTagTest { .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .description("description") .build() - assertThat(projectTag).isNotNull + assertThat(projectTag.id()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(projectTag.name()).isEqualTo("name") assertThat(projectTag.projectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTest.kt index 15ac6b29..7c374e5d 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTest.kt @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test internal class ProjectTest { @Test - fun createProject() { + fun create() { val project = Project.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -33,7 +33,7 @@ internal class ProjectTest { ) .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - assertThat(project).isNotNull + assertThat(project.id()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(project.name()).isEqualTo("name") assertThat(project.orgId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptDataTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptDataTest.kt index f0acad00..324272f3 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptDataTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptDataTest.kt @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test internal class PromptDataTest { @Test - fun createPromptData() { + fun create() { val promptData = PromptData.builder() .options( @@ -85,7 +85,7 @@ internal class PromptDataTest { .build() ) .build() - assertThat(promptData).isNotNull + assertThat(promptData.options()) .contains( PromptOptions.builder() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptOptionsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptOptionsTest.kt index 05a4e211..02303103 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptOptionsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptOptionsTest.kt @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test internal class PromptOptionsTest { @Test - fun createPromptOptions() { + fun create() { val promptOptions = PromptOptions.builder() .model("model") @@ -44,7 +44,7 @@ internal class PromptOptionsTest { ) .position("position") .build() - assertThat(promptOptions).isNotNull + assertThat(promptOptions.model()).contains("model") assertThat(promptOptions.params()) .contains( diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptTest.kt index 396bf20e..80570cb0 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptTest.kt @@ -11,7 +11,7 @@ import org.junit.jupiter.api.Test internal class PromptTest { @Test - fun createPrompt() { + fun create() { val prompt = Prompt.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -111,7 +111,7 @@ internal class PromptTest { ) .addTag("string") .build() - assertThat(prompt).isNotNull + assertThat(prompt.id()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(prompt._xactId()).isEqualTo("_xact_id") assertThat(prompt.logId()).isEqualTo(Prompt.LogId.P) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RepoInfoTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RepoInfoTest.kt index 402272fd..8903a668 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RepoInfoTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RepoInfoTest.kt @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test internal class RepoInfoTest { @Test - fun createRepoInfo() { + fun create() { val repoInfo = RepoInfo.builder() .authorEmail("author_email") @@ -21,7 +21,7 @@ internal class RepoInfoTest { .gitDiff("git_diff") .tag("tag") .build() - assertThat(repoInfo).isNotNull + assertThat(repoInfo.authorEmail()).contains("author_email") assertThat(repoInfo.authorName()).contains("author_name") assertThat(repoInfo.branch()).contains("branch") diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleTest.kt index bdfd04ed..2be027f8 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleTest.kt @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test internal class RoleTest { @Test - fun createRole() { + fun create() { val role = Role.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -28,7 +28,7 @@ internal class RoleTest { .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - assertThat(role).isNotNull + assertThat(role.id()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(role.name()).isEqualTo("name") assertThat(role.created()).contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ScoreSummaryTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ScoreSummaryTest.kt index e37b5561..faca9ae7 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ScoreSummaryTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ScoreSummaryTest.kt @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test internal class ScoreSummaryTest { @Test - fun createScoreSummary() { + fun create() { val scoreSummary = ScoreSummary.builder() .improvements(0L) @@ -17,7 +17,7 @@ internal class ScoreSummaryTest { .score(0.0) .diff(-1.0) .build() - assertThat(scoreSummary).isNotNull + assertThat(scoreSummary.improvements()).isEqualTo(0L) assertThat(scoreSummary.name()).isEqualTo("name") assertThat(scoreSummary.regressions()).isEqualTo(0L) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanAttributesTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanAttributesTest.kt index c8368446..9ca72654 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanAttributesTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanAttributesTest.kt @@ -8,9 +8,9 @@ import org.junit.jupiter.api.Test internal class SpanAttributesTest { @Test - fun createSpanAttributes() { + fun create() { val spanAttributes = SpanAttributes.builder().name("name").type(SpanType.LLM).build() - assertThat(spanAttributes).isNotNull + assertThat(spanAttributes.name()).contains("name") assertThat(spanAttributes.type()).contains(SpanType.LLM) } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIFrameTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIFrameTest.kt index 13eb4eef..2cc8a1ea 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIFrameTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIFrameTest.kt @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test internal class SpanIFrameTest { @Test - fun createSpanIFrame() { + fun create() { val spanIFrame = SpanIFrame.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -22,7 +22,7 @@ internal class SpanIFrameTest { .postMessage(true) .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - assertThat(spanIFrame).isNotNull + assertThat(spanIFrame.id()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(spanIFrame.name()).isEqualTo("name") assertThat(spanIFrame.projectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SummarizeDatasetResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SummarizeDatasetResponseTest.kt index 78017764..c1c3ded6 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SummarizeDatasetResponseTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SummarizeDatasetResponseTest.kt @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test internal class SummarizeDatasetResponseTest { @Test - fun createSummarizeDatasetResponse() { + fun create() { val summarizeDatasetResponse = SummarizeDatasetResponse.builder() .datasetName("dataset_name") @@ -17,7 +17,7 @@ internal class SummarizeDatasetResponseTest { .projectUrl("https://example.com") .dataSummary(DataSummary.builder().totalRecords(0L).build()) .build() - assertThat(summarizeDatasetResponse).isNotNull + assertThat(summarizeDatasetResponse.datasetName()).isEqualTo("dataset_name") assertThat(summarizeDatasetResponse.datasetUrl()).isEqualTo("https://example.com") assertThat(summarizeDatasetResponse.projectName()).isEqualTo("project_name") diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SummarizeExperimentResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SummarizeExperimentResponseTest.kt index 2b332170..7401a661 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SummarizeExperimentResponseTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SummarizeExperimentResponseTest.kt @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test internal class SummarizeExperimentResponseTest { @Test - fun createSummarizeExperimentResponse() { + fun create() { val summarizeExperimentResponse = SummarizeExperimentResponse.builder() .experimentName("experiment_name") @@ -51,7 +51,7 @@ internal class SummarizeExperimentResponseTest { .build() ) .build() - assertThat(summarizeExperimentResponse).isNotNull + assertThat(summarizeExperimentResponse.experimentName()).isEqualTo("experiment_name") assertThat(summarizeExperimentResponse.experimentUrl()).isEqualTo("https://example.com") assertThat(summarizeExperimentResponse.projectName()).isEqualTo("project_name") diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/UserTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/UserTest.kt index 56a1074a..e0e2d714 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/UserTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/UserTest.kt @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test internal class UserTest { @Test - fun createUser() { + fun create() { val user = User.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -19,7 +19,7 @@ internal class UserTest { .familyName("family_name") .givenName("given_name") .build() - assertThat(user).isNotNull + assertThat(user.id()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(user.avatarUrl()).contains("avatar_url") assertThat(user.created()).contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDataSearchTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDataSearchTest.kt index 959020e8..f62c7306 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDataSearchTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDataSearchTest.kt @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test internal class ViewDataSearchTest { @Test - fun createViewDataSearch() { + fun create() { val viewDataSearch = ViewDataSearch.builder() .addFilter(JsonValue.from(mapOf())) @@ -18,7 +18,7 @@ internal class ViewDataSearchTest { .addSort(JsonValue.from(mapOf())) .addTag(JsonValue.from(mapOf())) .build() - assertThat(viewDataSearch).isNotNull + assertThat(viewDataSearch.filter().getOrNull()) .containsExactly(JsonValue.from(mapOf())) assertThat(viewDataSearch.match().getOrNull()) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDataTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDataTest.kt index b1dabd9e..40def064 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDataTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDataTest.kt @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test internal class ViewDataTest { @Test - fun createViewData() { + fun create() { val viewData = ViewData.builder() .search( @@ -21,7 +21,7 @@ internal class ViewDataTest { .build() ) .build() - assertThat(viewData).isNotNull + assertThat(viewData.search()) .contains( ViewDataSearch.builder() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewOptionsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewOptionsTest.kt index 59d5b6b7..83b7a843 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewOptionsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewOptionsTest.kt @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test internal class ViewOptionsTest { @Test - fun createViewOptions() { + fun create() { val viewOptions = ViewOptions.builder() .addColumnOrder("string") @@ -28,7 +28,7 @@ internal class ViewOptionsTest { .layout("layout") .rowHeight("rowHeight") .build() - assertThat(viewOptions).isNotNull + assertThat(viewOptions.columnOrder().getOrNull()).containsExactly("string") assertThat(viewOptions.columnSizing()) .contains( diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewTest.kt index e8ba2a61..b5b66680 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewTest.kt @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test internal class ViewTest { @Test - fun createView() { + fun create() { val view = View.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -52,7 +52,7 @@ internal class ViewTest { .build() ) .build() - assertThat(view).isNotNull + assertThat(view.id()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(view.name()).isEqualTo("name") assertThat(view.objectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") From c9856ed81fdfa4f17bdb96d66e45adc2751d4846 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 19 Mar 2025 14:18:00 +0000 Subject: [PATCH 04/42] fix(client): support kotlin 1.8 runtime (#161) --- braintrust-java-example/build.gradle.kts | 10 +++++--- buildSrc/build.gradle.kts | 4 +-- .../main/kotlin/braintrust.java.gradle.kts | 3 +++ .../main/kotlin/braintrust.kotlin.gradle.kts | 25 ++++++++++--------- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/braintrust-java-example/build.gradle.kts b/braintrust-java-example/build.gradle.kts index c64a1556..df9438d5 100644 --- a/braintrust-java-example/build.gradle.kts +++ b/braintrust-java-example/build.gradle.kts @@ -1,16 +1,20 @@ plugins { - id("braintrust.kotlin") id("java") application } +repositories { + mavenCentral() +} + dependencies { implementation(project(":braintrust-java")) } -tasks.withType().configureEach { +java { // Allow using more modern APIs, like `List.of` and `Map.of`, in examples. - options.release.set(9) + sourceCompatibility = JavaVersion.VERSION_1_9 + targetCompatibility = JavaVersion.VERSION_1_9 } application { diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index d1ed374d..778c89de 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -1,6 +1,6 @@ plugins { `kotlin-dsl` - kotlin("jvm") version "2.1.10" + kotlin("jvm") version "1.9.20" id("com.vanniktech.maven.publish") version "0.28.0" } @@ -11,6 +11,6 @@ repositories { dependencies { implementation("com.diffplug.spotless:spotless-plugin-gradle:7.0.2") - implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.1.10") + implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.20") implementation("com.vanniktech:gradle-maven-publish-plugin:0.28.0") } diff --git a/buildSrc/src/main/kotlin/braintrust.java.gradle.kts b/buildSrc/src/main/kotlin/braintrust.java.gradle.kts index 597b6e80..e39d9ac6 100755 --- a/buildSrc/src/main/kotlin/braintrust.java.gradle.kts +++ b/buildSrc/src/main/kotlin/braintrust.java.gradle.kts @@ -23,6 +23,9 @@ java { toolchain { languageVersion.set(JavaLanguageVersion.of(17)) } + + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 } tasks.withType().configureEach { diff --git a/buildSrc/src/main/kotlin/braintrust.kotlin.gradle.kts b/buildSrc/src/main/kotlin/braintrust.kotlin.gradle.kts index ff8a82d8..51f8461b 100755 --- a/buildSrc/src/main/kotlin/braintrust.kotlin.gradle.kts +++ b/buildSrc/src/main/kotlin/braintrust.kotlin.gradle.kts @@ -1,6 +1,6 @@ import com.diffplug.gradle.spotless.SpotlessExtension import org.jetbrains.kotlin.gradle.dsl.JvmTarget -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import org.jetbrains.kotlin.gradle.dsl.KotlinVersion plugins { id("braintrust.java") @@ -11,25 +11,26 @@ kotlin { jvmToolchain { languageVersion.set(JavaLanguageVersion.of(17)) } -} - -configure { - kotlin { - ktfmt().kotlinlangStyle() - toggleOffOn() - } -} -tasks.withType().configureEach { compilerOptions { - allWarningsAsErrors = true freeCompilerArgs = listOf( "-Xjvm-default=all", "-Xjdk-release=1.8", // Suppress deprecation warnings because we may still reference and test deprecated members. - "-Xsuppress-warning=DEPRECATION" + // TODO: Replace with `-Xsuppress-warning=DEPRECATION` once we use Kotlin compiler 2.1.0+. + "-nowarn", ) jvmTarget.set(JvmTarget.JVM_1_8) + languageVersion.set(KotlinVersion.KOTLIN_1_8) + apiVersion.set(KotlinVersion.KOTLIN_1_8) + coreLibrariesVersion = "1.8.0" + } +} + +configure { + kotlin { + ktfmt().kotlinlangStyle() + toggleOffOn() } } From a490f5fb5977d5347814c0d29a022468c8793e65 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 19 Mar 2025 14:23:46 +0000 Subject: [PATCH 05/42] chore(internal): codegen related update (#162) --- .../kotlin/com/braintrustdata/api/models/AclListParams.kt | 2 +- .../kotlin/com/braintrustdata/api/models/EnvVarListParams.kt | 2 +- .../com/braintrustdata/api/models/ProjectScoreListParams.kt | 4 ++-- .../kotlin/com/braintrustdata/api/models/ViewListParams.kt | 4 ++-- .../com/braintrustdata/api/models/ViewRetrieveParams.kt | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListParams.kt index a49c07f5..be85a24f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListParams.kt @@ -82,7 +82,7 @@ private constructor( QueryParams.builder() .apply { put("object_id", objectId) - put("object_type", objectType.asString()) + put("object_type", objectType.toString()) endingBefore?.let { put("ending_before", it) } ids?.accept( object : Ids.Visitor { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListParams.kt index 4977d934..b4633176 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListParams.kt @@ -78,7 +78,7 @@ private constructor( ) limit?.let { put("limit", it.toString()) } objectId?.let { put("object_id", it) } - objectType?.let { put("object_type", it.asString()) } + objectType?.let { put("object_type", it.toString()) } putAll(additionalQueryParams) } .build() diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListParams.kt index a1946a16..14f151cd 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListParams.kt @@ -112,13 +112,13 @@ private constructor( scoreType?.accept( object : ScoreType.Visitor { override fun visitProject(project: ProjectScoreType) { - put("score_type", project.asString()) + put("score_type", project.toString()) } override fun visitProjectScoreTypes( projectScoreTypes: List ) { - put("score_type", projectScoreTypes.joinToString(",") { it.asString() }) + put("score_type", projectScoreTypes.joinToString(",") { it.toString() }) } } ) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListParams.kt index ef2525d5..26430c16 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListParams.kt @@ -90,7 +90,7 @@ private constructor( QueryParams.builder() .apply { put("object_id", objectId) - put("object_type", objectType.asString()) + put("object_type", objectType.toString()) endingBefore?.let { put("ending_before", it) } ids?.accept( object : Ids.Visitor { @@ -106,7 +106,7 @@ private constructor( limit?.let { put("limit", it.toString()) } startingAfter?.let { put("starting_after", it) } viewName?.let { put("view_name", it) } - viewType?.let { put("view_type", it.asString()) } + viewType?.let { put("view_type", it.toString()) } putAll(additionalQueryParams) } .build() diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewRetrieveParams.kt index 6cb34a1e..ae36c399 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewRetrieveParams.kt @@ -44,7 +44,7 @@ private constructor( QueryParams.builder() .apply { put("object_id", objectId) - put("object_type", objectType.asString()) + put("object_type", objectType.toString()) putAll(additionalQueryParams) } .build() From 140986d47b0e2f62d5ba3b84d459784e683fcda8 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 20 Mar 2025 07:20:32 +0000 Subject: [PATCH 06/42] chore(internal): codegen related update (#163) --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 3e33c451..1ec03da4 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,12 @@ The Braintrust Java SDK is similar to the Braintrust Kotlin SDK but with minor d It is generated with [Stainless](https://www.stainless.com/). + + The REST API documentation can be found on [www.braintrustdata.com](https://www.braintrustdata.com/docs/api/spec). Javadocs are also available on [javadoc.io](https://javadoc.io/doc/com.braintrustdata.api/braintrust-java/0.8.0). + + ## Installation From 8463834733a95f1afc905f3cfa74793b458e9a5a Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 20 Mar 2025 07:47:55 +0000 Subject: [PATCH 07/42] chore(client)!: refactor exception structure and methods (#164) # Migration Previously you would access error JSON on an exception via `exception.error()._additionalProperties()`, which would return `Map`. Now you would access this via `exception.body()`, which returns `JsonValue`. You should no longer assume that the returned error JSON is an object. You can check via `exception.body().asObject()`. --- .../api/core/handlers/ErrorHandler.kt | 149 +++++++----------- .../api/errors/BadRequestException.kt | 78 ++++++++- .../api/errors/BraintrustError.kt | 82 ---------- .../api/errors/BraintrustServiceException.kt | 22 +-- .../api/errors/InternalServerException.kt | 93 ++++++++++- .../api/errors/NotFoundException.kt | 74 ++++++++- .../api/errors/PermissionDeniedException.kt | 78 ++++++++- .../api/errors/RateLimitException.kt | 78 ++++++++- .../api/errors/UnauthorizedException.kt | 78 ++++++++- .../errors/UnexpectedStatusCodeException.kt | 94 ++++++++++- .../errors/UnprocessableEntityException.kt | 78 ++++++++- .../api/services/async/AclServiceAsyncImpl.kt | 4 +- .../async/AiSecretServiceAsyncImpl.kt | 4 +- .../services/async/ApiKeyServiceAsyncImpl.kt | 4 +- .../services/async/DatasetServiceAsyncImpl.kt | 4 +- .../services/async/EnvVarServiceAsyncImpl.kt | 4 +- .../services/async/EvalServiceAsyncImpl.kt | 4 +- .../async/ExperimentServiceAsyncImpl.kt | 4 +- .../async/FunctionServiceAsyncImpl.kt | 4 +- .../services/async/GroupServiceAsyncImpl.kt | 4 +- .../async/OrganizationServiceAsyncImpl.kt | 4 +- .../async/ProjectScoreServiceAsyncImpl.kt | 4 +- .../services/async/ProjectServiceAsyncImpl.kt | 4 +- .../async/ProjectTagServiceAsyncImpl.kt | 4 +- .../services/async/PromptServiceAsyncImpl.kt | 4 +- .../services/async/RoleServiceAsyncImpl.kt | 4 +- .../async/SpanIframeServiceAsyncImpl.kt | 4 +- .../async/TopLevelServiceAsyncImpl.kt | 4 +- .../services/async/UserServiceAsyncImpl.kt | 4 +- .../services/async/ViewServiceAsyncImpl.kt | 4 +- .../organizations/MemberServiceAsyncImpl.kt | 4 +- .../async/projects/LogServiceAsyncImpl.kt | 4 +- .../api/services/blocking/AclServiceImpl.kt | 4 +- .../services/blocking/AiSecretServiceImpl.kt | 4 +- .../services/blocking/ApiKeyServiceImpl.kt | 4 +- .../services/blocking/DatasetServiceImpl.kt | 4 +- .../services/blocking/EnvVarServiceImpl.kt | 4 +- .../api/services/blocking/EvalServiceImpl.kt | 4 +- .../blocking/ExperimentServiceImpl.kt | 4 +- .../services/blocking/FunctionServiceImpl.kt | 4 +- .../api/services/blocking/GroupServiceImpl.kt | 4 +- .../blocking/OrganizationServiceImpl.kt | 4 +- .../blocking/ProjectScoreServiceImpl.kt | 4 +- .../services/blocking/ProjectServiceImpl.kt | 4 +- .../blocking/ProjectTagServiceImpl.kt | 4 +- .../services/blocking/PromptServiceImpl.kt | 4 +- .../api/services/blocking/RoleServiceImpl.kt | 4 +- .../blocking/SpanIframeServiceImpl.kt | 4 +- .../services/blocking/TopLevelServiceImpl.kt | 4 +- .../api/services/blocking/UserServiceImpl.kt | 4 +- .../api/services/blocking/ViewServiceImpl.kt | 4 +- .../organizations/MemberServiceImpl.kt | 4 +- .../blocking/projects/LogServiceImpl.kt | 4 +- .../api/services/ErrorHandlingTest.kt | 56 ++++--- 54 files changed, 807 insertions(+), 321 deletions(-) delete mode 100755 braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BraintrustError.kt diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/handlers/ErrorHandler.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/handlers/ErrorHandler.kt index 12cfc384..f3b14814 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/handlers/ErrorHandler.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/handlers/ErrorHandler.kt @@ -1,12 +1,14 @@ +// File generated from our OpenAPI spec by Stainless. + @file:JvmName("ErrorHandler") package com.braintrustdata.api.core.handlers -import com.braintrustdata.api.core.http.Headers +import com.braintrustdata.api.core.JsonMissing +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.errors.BadRequestException -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.errors.InternalServerException import com.braintrustdata.api.errors.NotFoundException import com.braintrustdata.api.errors.PermissionDeniedException @@ -15,111 +17,68 @@ import com.braintrustdata.api.errors.UnauthorizedException import com.braintrustdata.api.errors.UnexpectedStatusCodeException import com.braintrustdata.api.errors.UnprocessableEntityException import com.fasterxml.jackson.databind.json.JsonMapper -import java.io.ByteArrayInputStream -import java.io.InputStream @JvmSynthetic -internal fun errorHandler(jsonMapper: JsonMapper): Handler { - val handler = jsonHandler(jsonMapper) +internal fun errorHandler(jsonMapper: JsonMapper): Handler { + val handler = jsonHandler(jsonMapper) - return object : Handler { - override fun handle(response: HttpResponse): BraintrustError = + return object : Handler { + override fun handle(response: HttpResponse): JsonValue = try { handler.handle(response) } catch (e: Exception) { - BraintrustError.builder().build() + JsonMissing.of() } } } @JvmSynthetic -internal fun Handler.withErrorHandler(errorHandler: Handler): Handler = +internal fun Handler.withErrorHandler(errorHandler: Handler): Handler = object : Handler { - override fun handle(response: HttpResponse): T { + override fun handle(response: HttpResponse): T = when (val statusCode = response.statusCode()) { - in 200..299 -> { - return this@withErrorHandler.handle(response) - } - 400 -> { - val buffered = response.buffered() - throw BadRequestException( - buffered.headers(), - stringHandler().handle(buffered), - errorHandler.handle(buffered), - ) - } - 401 -> { - val buffered = response.buffered() - throw UnauthorizedException( - buffered.headers(), - stringHandler().handle(buffered), - errorHandler.handle(buffered), - ) - } - 403 -> { - val buffered = response.buffered() - throw PermissionDeniedException( - buffered.headers(), - stringHandler().handle(buffered), - errorHandler.handle(buffered), - ) - } - 404 -> { - val buffered = response.buffered() - throw NotFoundException( - buffered.headers(), - stringHandler().handle(buffered), - errorHandler.handle(buffered), - ) - } - 422 -> { - val buffered = response.buffered() - throw UnprocessableEntityException( - buffered.headers(), - stringHandler().handle(buffered), - errorHandler.handle(buffered), - ) - } - 429 -> { - val buffered = response.buffered() - throw RateLimitException( - buffered.headers(), - stringHandler().handle(buffered), - errorHandler.handle(buffered), - ) - } - in 500..599 -> { - val buffered = response.buffered() - throw InternalServerException( - statusCode, - buffered.headers(), - stringHandler().handle(buffered), - errorHandler.handle(buffered), - ) - } - else -> { - val buffered = response.buffered() - throw UnexpectedStatusCodeException( - statusCode, - buffered.headers(), - stringHandler().handle(buffered), - errorHandler.handle(buffered), - ) - } + in 200..299 -> this@withErrorHandler.handle(response) + 400 -> + throw BadRequestException.builder() + .headers(response.headers()) + .body(errorHandler.handle(response)) + .build() + 401 -> + throw UnauthorizedException.builder() + .headers(response.headers()) + .body(errorHandler.handle(response)) + .build() + 403 -> + throw PermissionDeniedException.builder() + .headers(response.headers()) + .body(errorHandler.handle(response)) + .build() + 404 -> + throw NotFoundException.builder() + .headers(response.headers()) + .body(errorHandler.handle(response)) + .build() + 422 -> + throw UnprocessableEntityException.builder() + .headers(response.headers()) + .body(errorHandler.handle(response)) + .build() + 429 -> + throw RateLimitException.builder() + .headers(response.headers()) + .body(errorHandler.handle(response)) + .build() + in 500..599 -> + throw InternalServerException.builder() + .statusCode(statusCode) + .headers(response.headers()) + .body(errorHandler.handle(response)) + .build() + else -> + throw UnexpectedStatusCodeException.builder() + .statusCode(statusCode) + .headers(response.headers()) + .body(errorHandler.handle(response)) + .build() } - } - } - -private fun HttpResponse.buffered(): HttpResponse { - val body = body().readBytes() - - return object : HttpResponse { - override fun statusCode(): Int = this@buffered.statusCode() - - override fun headers(): Headers = this@buffered.headers() - - override fun body(): InputStream = ByteArrayInputStream(body) - - override fun close() = this@buffered.close() } -} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BadRequestException.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BadRequestException.kt index b8c65254..4f0ec4e2 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BadRequestException.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BadRequestException.kt @@ -1,6 +1,80 @@ +// File generated from our OpenAPI spec by Stainless. + package com.braintrustdata.api.errors +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class BadRequestException +private constructor(private val headers: Headers, private val body: JsonValue, cause: Throwable?) : + BraintrustServiceException("400: $body", cause) { + + override fun headers(): Headers = headers + + override fun body(): JsonValue = body + + override fun statusCode(): Int = 400 + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [BadRequestException]. + * + * The following fields are required: + * ```java + * .headers() + * .body() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BadRequestException]. */ + class Builder internal constructor() { + + private var headers: Headers? = null + private var body: JsonValue? = null + private var cause: Throwable? = null + + @JvmSynthetic + internal fun from(badRequestException: BadRequestException) = apply { + headers = badRequestException.headers + body = badRequestException.body + cause = badRequestException.cause + } + + fun headers(headers: Headers) = apply { this.headers = headers } + + fun body(body: JsonValue) = apply { this.body = body } + + fun cause(cause: Throwable?) = apply { this.cause = cause } + + /** Alias for calling [Builder.cause] with `cause.orElse(null)`. */ + fun cause(cause: Optional) = cause(cause.getOrNull()) -class BadRequestException(headers: Headers, body: String, error: BraintrustError) : - BraintrustServiceException(400, headers, body, error) + /** + * Returns an immutable instance of [BadRequestException]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .headers() + * .body() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BadRequestException = + BadRequestException( + checkRequired("headers", headers), + checkRequired("body", body), + cause, + ) + } +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BraintrustError.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BraintrustError.kt deleted file mode 100755 index 42865ed6..00000000 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BraintrustError.kt +++ /dev/null @@ -1,82 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.braintrustdata.api.errors - -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import java.util.Objects - -@NoAutoDetect -class BraintrustError -@JsonCreator -private constructor( - @JsonAnyGetter - @ExcludeMissing - @JsonAnySetter - @get:JvmName("additionalProperties") - val additionalProperties: Map = immutableEmptyMap() -) { - - fun toBuilder() = Builder().from(this) - - companion object { - - /** Returns a mutable builder for constructing an instance of [BraintrustError]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [BraintrustError]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(braintrustError: BraintrustError) = apply { - additionalProperties = braintrustError.additionalProperties.toMutableMap() - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - 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) - } - - /** - * Returns an immutable instance of [BraintrustError]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): BraintrustError = BraintrustError(additionalProperties.toImmutable()) - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is BraintrustError && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(additionalProperties) /* spotless:on */ - - override fun toString() = "BraintrustError{additionalProperties=$additionalProperties}" -} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BraintrustServiceException.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BraintrustServiceException.kt index 728ac6bd..ebb6267b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BraintrustServiceException.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BraintrustServiceException.kt @@ -1,23 +1,17 @@ +// File generated from our OpenAPI spec by Stainless. + package com.braintrustdata.api.errors +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.http.Headers abstract class BraintrustServiceException -@JvmOverloads -constructor( - private val statusCode: Int, - private val headers: Headers, - private val body: String, - private val error: BraintrustError, - message: String = "$statusCode: $error", - cause: Throwable? = null, -) : BraintrustException(message, cause) { - - fun statusCode(): Int = statusCode +protected constructor(message: String, cause: Throwable? = null) : + BraintrustException(message, cause) { - fun headers(): Headers = headers + abstract fun statusCode(): Int - fun body(): String = body + abstract fun headers(): Headers - fun error(): BraintrustError = error + abstract fun body(): JsonValue } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/InternalServerException.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/InternalServerException.kt index 36cc4432..9834c41a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/InternalServerException.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/InternalServerException.kt @@ -1,10 +1,91 @@ +// File generated from our OpenAPI spec by Stainless. + package com.braintrustdata.api.errors +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class InternalServerException +private constructor( + private val statusCode: Int, + private val headers: Headers, + private val body: JsonValue, + cause: Throwable?, +) : BraintrustServiceException("$statusCode: $body", cause) { + + override fun statusCode(): Int = statusCode + + override fun headers(): Headers = headers + + override fun body(): JsonValue = body + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [InternalServerException]. + * + * The following fields are required: + * ```java + * .statusCode() + * .headers() + * .body() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InternalServerException]. */ + class Builder internal constructor() { + + private var statusCode: Int? = null + private var headers: Headers? = null + private var body: JsonValue? = null + private var cause: Throwable? = null + + @JvmSynthetic + internal fun from(internalServerException: InternalServerException) = apply { + statusCode = internalServerException.statusCode + headers = internalServerException.headers + body = internalServerException.body + cause = internalServerException.cause + } + + fun statusCode(statusCode: Int) = apply { this.statusCode = statusCode } + + fun headers(headers: Headers) = apply { this.headers = headers } + + fun body(body: JsonValue) = apply { this.body = body } + + fun cause(cause: Throwable?) = apply { this.cause = cause } + + /** Alias for calling [Builder.cause] with `cause.orElse(null)`. */ + fun cause(cause: Optional) = cause(cause.getOrNull()) -class InternalServerException( - statusCode: Int, - headers: Headers, - body: String, - error: BraintrustError, -) : BraintrustServiceException(statusCode, headers, body, error) + /** + * Returns an immutable instance of [InternalServerException]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .statusCode() + * .headers() + * .body() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): InternalServerException = + InternalServerException( + checkRequired("statusCode", statusCode), + checkRequired("headers", headers), + checkRequired("body", body), + cause, + ) + } +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/NotFoundException.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/NotFoundException.kt index ecc1a307..2d0ca370 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/NotFoundException.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/NotFoundException.kt @@ -1,6 +1,76 @@ +// File generated from our OpenAPI spec by Stainless. + package com.braintrustdata.api.errors +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class NotFoundException +private constructor(private val headers: Headers, private val body: JsonValue, cause: Throwable?) : + BraintrustServiceException("404: $body", cause) { + + override fun headers(): Headers = headers + + override fun body(): JsonValue = body + + override fun statusCode(): Int = 404 + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [NotFoundException]. + * + * The following fields are required: + * ```java + * .headers() + * .body() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [NotFoundException]. */ + class Builder internal constructor() { + + private var headers: Headers? = null + private var body: JsonValue? = null + private var cause: Throwable? = null + + @JvmSynthetic + internal fun from(notFoundException: NotFoundException) = apply { + headers = notFoundException.headers + body = notFoundException.body + cause = notFoundException.cause + } + + fun headers(headers: Headers) = apply { this.headers = headers } + + fun body(body: JsonValue) = apply { this.body = body } + + fun cause(cause: Throwable?) = apply { this.cause = cause } + + /** Alias for calling [Builder.cause] with `cause.orElse(null)`. */ + fun cause(cause: Optional) = cause(cause.getOrNull()) -class NotFoundException(headers: Headers, body: String, error: BraintrustError) : - BraintrustServiceException(404, headers, body, error) + /** + * Returns an immutable instance of [NotFoundException]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .headers() + * .body() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): NotFoundException = + NotFoundException(checkRequired("headers", headers), checkRequired("body", body), cause) + } +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/PermissionDeniedException.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/PermissionDeniedException.kt index 27380e3e..7270819a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/PermissionDeniedException.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/PermissionDeniedException.kt @@ -1,6 +1,80 @@ +// File generated from our OpenAPI spec by Stainless. + package com.braintrustdata.api.errors +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class PermissionDeniedException +private constructor(private val headers: Headers, private val body: JsonValue, cause: Throwable?) : + BraintrustServiceException("403: $body", cause) { + + override fun headers(): Headers = headers + + override fun body(): JsonValue = body + + override fun statusCode(): Int = 403 + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [PermissionDeniedException]. + * + * The following fields are required: + * ```java + * .headers() + * .body() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PermissionDeniedException]. */ + class Builder internal constructor() { + + private var headers: Headers? = null + private var body: JsonValue? = null + private var cause: Throwable? = null + + @JvmSynthetic + internal fun from(permissionDeniedException: PermissionDeniedException) = apply { + headers = permissionDeniedException.headers + body = permissionDeniedException.body + cause = permissionDeniedException.cause + } + + fun headers(headers: Headers) = apply { this.headers = headers } + + fun body(body: JsonValue) = apply { this.body = body } + + fun cause(cause: Throwable?) = apply { this.cause = cause } + + /** Alias for calling [Builder.cause] with `cause.orElse(null)`. */ + fun cause(cause: Optional) = cause(cause.getOrNull()) -class PermissionDeniedException(headers: Headers, body: String, error: BraintrustError) : - BraintrustServiceException(403, headers, body, error) + /** + * Returns an immutable instance of [PermissionDeniedException]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .headers() + * .body() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PermissionDeniedException = + PermissionDeniedException( + checkRequired("headers", headers), + checkRequired("body", body), + cause, + ) + } +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/RateLimitException.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/RateLimitException.kt index a9352a3a..79d7d627 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/RateLimitException.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/RateLimitException.kt @@ -1,6 +1,80 @@ +// File generated from our OpenAPI spec by Stainless. + package com.braintrustdata.api.errors +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class RateLimitException +private constructor(private val headers: Headers, private val body: JsonValue, cause: Throwable?) : + BraintrustServiceException("429: $body", cause) { + + override fun headers(): Headers = headers + + override fun body(): JsonValue = body + + override fun statusCode(): Int = 429 + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [RateLimitException]. + * + * The following fields are required: + * ```java + * .headers() + * .body() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RateLimitException]. */ + class Builder internal constructor() { + + private var headers: Headers? = null + private var body: JsonValue? = null + private var cause: Throwable? = null + + @JvmSynthetic + internal fun from(rateLimitException: RateLimitException) = apply { + headers = rateLimitException.headers + body = rateLimitException.body + cause = rateLimitException.cause + } + + fun headers(headers: Headers) = apply { this.headers = headers } + + fun body(body: JsonValue) = apply { this.body = body } + + fun cause(cause: Throwable?) = apply { this.cause = cause } + + /** Alias for calling [Builder.cause] with `cause.orElse(null)`. */ + fun cause(cause: Optional) = cause(cause.getOrNull()) -class RateLimitException(headers: Headers, body: String, error: BraintrustError) : - BraintrustServiceException(429, headers, body, error) + /** + * Returns an immutable instance of [RateLimitException]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .headers() + * .body() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RateLimitException = + RateLimitException( + checkRequired("headers", headers), + checkRequired("body", body), + cause, + ) + } +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/UnauthorizedException.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/UnauthorizedException.kt index 57f9242f..e7cf6f20 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/UnauthorizedException.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/UnauthorizedException.kt @@ -1,6 +1,80 @@ +// File generated from our OpenAPI spec by Stainless. + package com.braintrustdata.api.errors +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class UnauthorizedException +private constructor(private val headers: Headers, private val body: JsonValue, cause: Throwable?) : + BraintrustServiceException("401: $body", cause) { + + override fun headers(): Headers = headers + + override fun body(): JsonValue = body + + override fun statusCode(): Int = 401 + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [UnauthorizedException]. + * + * The following fields are required: + * ```java + * .headers() + * .body() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UnauthorizedException]. */ + class Builder internal constructor() { + + private var headers: Headers? = null + private var body: JsonValue? = null + private var cause: Throwable? = null + + @JvmSynthetic + internal fun from(unauthorizedException: UnauthorizedException) = apply { + headers = unauthorizedException.headers + body = unauthorizedException.body + cause = unauthorizedException.cause + } + + fun headers(headers: Headers) = apply { this.headers = headers } + + fun body(body: JsonValue) = apply { this.body = body } + + fun cause(cause: Throwable?) = apply { this.cause = cause } + + /** Alias for calling [Builder.cause] with `cause.orElse(null)`. */ + fun cause(cause: Optional) = cause(cause.getOrNull()) -class UnauthorizedException(headers: Headers, body: String, error: BraintrustError) : - BraintrustServiceException(401, headers, body, error) + /** + * Returns an immutable instance of [UnauthorizedException]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .headers() + * .body() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UnauthorizedException = + UnauthorizedException( + checkRequired("headers", headers), + checkRequired("body", body), + cause, + ) + } +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/UnexpectedStatusCodeException.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/UnexpectedStatusCodeException.kt index 7aa10d9b..f463ecdd 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/UnexpectedStatusCodeException.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/UnexpectedStatusCodeException.kt @@ -1,10 +1,92 @@ +// File generated from our OpenAPI spec by Stainless. + package com.braintrustdata.api.errors +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class UnexpectedStatusCodeException +private constructor( + private val statusCode: Int, + private val headers: Headers, + private val body: JsonValue, + cause: Throwable?, +) : BraintrustServiceException("$statusCode: $body", cause) { + + override fun statusCode(): Int = statusCode + + override fun headers(): Headers = headers + + override fun body(): JsonValue = body + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [UnexpectedStatusCodeException]. + * + * The following fields are required: + * ```java + * .statusCode() + * .headers() + * .body() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UnexpectedStatusCodeException]. */ + class Builder internal constructor() { + + private var statusCode: Int? = null + private var headers: Headers? = null + private var body: JsonValue? = null + private var cause: Throwable? = null + + @JvmSynthetic + internal fun from(unexpectedStatusCodeException: UnexpectedStatusCodeException) = apply { + statusCode = unexpectedStatusCodeException.statusCode + headers = unexpectedStatusCodeException.headers + body = unexpectedStatusCodeException.body + cause = unexpectedStatusCodeException.cause + } + + fun statusCode(statusCode: Int) = apply { this.statusCode = statusCode } + + fun headers(headers: Headers) = apply { this.headers = headers } + + fun body(body: JsonValue) = apply { this.body = body } + + fun cause(cause: Throwable?) = apply { this.cause = cause } + + /** Alias for calling [Builder.cause] with `cause.orElse(null)`. */ + fun cause(cause: Optional) = cause(cause.getOrNull()) -class UnexpectedStatusCodeException( - statusCode: Int, - headers: Headers, - body: String, - error: BraintrustError, -) : BraintrustServiceException(statusCode, headers, body, error) + /** + * Returns an immutable instance of [UnexpectedStatusCodeException]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .statusCode() + * .headers() + * .body() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UnexpectedStatusCodeException = + UnexpectedStatusCodeException( + checkRequired("statusCode", statusCode), + checkRequired("headers", headers), + checkRequired("body", body), + cause, + ) + } +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/UnprocessableEntityException.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/UnprocessableEntityException.kt index 6e216b4e..a4d91061 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/UnprocessableEntityException.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/UnprocessableEntityException.kt @@ -1,6 +1,80 @@ +// File generated from our OpenAPI spec by Stainless. + package com.braintrustdata.api.errors +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class UnprocessableEntityException +private constructor(private val headers: Headers, private val body: JsonValue, cause: Throwable?) : + BraintrustServiceException("422: $body", cause) { + + override fun headers(): Headers = headers + + override fun body(): JsonValue = body + + override fun statusCode(): Int = 422 + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [UnprocessableEntityException]. + * + * The following fields are required: + * ```java + * .headers() + * .body() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UnprocessableEntityException]. */ + class Builder internal constructor() { + + private var headers: Headers? = null + private var body: JsonValue? = null + private var cause: Throwable? = null + + @JvmSynthetic + internal fun from(unprocessableEntityException: UnprocessableEntityException) = apply { + headers = unprocessableEntityException.headers + body = unprocessableEntityException.body + cause = unprocessableEntityException.cause + } + + fun headers(headers: Headers) = apply { this.headers = headers } + + fun body(body: JsonValue) = apply { this.body = body } + + fun cause(cause: Throwable?) = apply { this.cause = cause } + + /** Alias for calling [Builder.cause] with `cause.orElse(null)`. */ + fun cause(cause: Optional) = cause(cause.getOrNull()) -class UnprocessableEntityException(headers: Headers, body: String, error: BraintrustError) : - BraintrustServiceException(422, headers, body, error) + /** + * Returns an immutable instance of [UnprocessableEntityException]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .headers() + * .body() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UnprocessableEntityException = + UnprocessableEntityException( + checkRequired("headers", headers), + checkRequired("body", body), + cause, + ) + } +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AclServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AclServiceAsyncImpl.kt index cbd003e7..002305b8 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AclServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AclServiceAsyncImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepareAsync -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.Acl import com.braintrustdata.api.models.AclBatchUpdateParams import com.braintrustdata.api.models.AclBatchUpdateResponse @@ -80,7 +80,7 @@ class AclServiceAsyncImpl internal constructor(private val clientOptions: Client class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : AclServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsyncImpl.kt index f1d13c8b..6ebbadb1 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsyncImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepareAsync -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.AISecret import com.braintrustdata.api.models.AiSecretCreateParams import com.braintrustdata.api.models.AiSecretDeleteParams @@ -87,7 +87,7 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : AiSecretServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsyncImpl.kt index 1de80f7e..0d7a9262 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsyncImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepareAsync -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.ApiKey import com.braintrustdata.api.models.ApiKeyCreateParams import com.braintrustdata.api.models.ApiKeyDeleteParams @@ -64,7 +64,7 @@ class ApiKeyServiceAsyncImpl internal constructor(private val clientOptions: Cli class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ApiKeyServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsyncImpl.kt index 90c60136..ae50c95f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsyncImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepareAsync -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.Dataset import com.braintrustdata.api.models.DatasetCreateParams import com.braintrustdata.api.models.DatasetDeleteParams @@ -115,7 +115,7 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : DatasetServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EnvVarServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EnvVarServiceAsyncImpl.kt index 6a418414..a3480f74 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EnvVarServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EnvVarServiceAsyncImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepareAsync -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.EnvVar import com.braintrustdata.api.models.EnvVarCreateParams import com.braintrustdata.api.models.EnvVarDeleteParams @@ -79,7 +79,7 @@ class EnvVarServiceAsyncImpl internal constructor(private val clientOptions: Cli class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : EnvVarServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EvalServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EvalServiceAsyncImpl.kt index d0fc0019..619ae690 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EvalServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EvalServiceAsyncImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepareAsync -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.EvalCreateParams import com.braintrustdata.api.models.SummarizeExperimentResponse import java.util.concurrent.CompletableFuture @@ -38,7 +38,7 @@ class EvalServiceAsyncImpl internal constructor(private val clientOptions: Clien class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : EvalServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsyncImpl.kt index 6e013716..0bf6bb72 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsyncImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepareAsync -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.Experiment import com.braintrustdata.api.models.ExperimentCreateParams import com.braintrustdata.api.models.ExperimentDeleteParams @@ -115,7 +115,7 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ExperimentServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsyncImpl.kt index aac9e675..2fc58ddd 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsyncImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepareAsync -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.Function import com.braintrustdata.api.models.FunctionCreateParams import com.braintrustdata.api.models.FunctionDeleteParams @@ -89,7 +89,7 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : FunctionServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/GroupServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/GroupServiceAsyncImpl.kt index 0c1a8fb9..680df37e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/GroupServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/GroupServiceAsyncImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepareAsync -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.Group import com.braintrustdata.api.models.GroupCreateParams import com.braintrustdata.api.models.GroupDeleteParams @@ -79,7 +79,7 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : GroupServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsyncImpl.kt index f85808a0..a314f29b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsyncImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepareAsync -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.Organization import com.braintrustdata.api.models.OrganizationDeleteParams import com.braintrustdata.api.models.OrganizationListPageAsync @@ -69,7 +69,7 @@ class OrganizationServiceAsyncImpl internal constructor(private val clientOption class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : OrganizationServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val members: MemberServiceAsync.WithRawResponse by lazy { MemberServiceAsyncImpl.WithRawResponseImpl(clientOptions) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsyncImpl.kt index f54aaad8..a3a90f99 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsyncImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepareAsync -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.ProjectScore import com.braintrustdata.api.models.ProjectScoreCreateParams import com.braintrustdata.api.models.ProjectScoreDeleteParams @@ -79,7 +79,7 @@ class ProjectScoreServiceAsyncImpl internal constructor(private val clientOption class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ProjectScoreServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsyncImpl.kt index ca777a86..ed4539e4 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsyncImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepareAsync -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.Project import com.braintrustdata.api.models.ProjectCreateParams import com.braintrustdata.api.models.ProjectDeleteParams @@ -77,7 +77,7 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ProjectServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val logs: LogServiceAsync.WithRawResponse by lazy { LogServiceAsyncImpl.WithRawResponseImpl(clientOptions) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsyncImpl.kt index ed1784d6..ca6f111e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsyncImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepareAsync -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.ProjectTag import com.braintrustdata.api.models.ProjectTagCreateParams import com.braintrustdata.api.models.ProjectTagDeleteParams @@ -79,7 +79,7 @@ class ProjectTagServiceAsyncImpl internal constructor(private val clientOptions: class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ProjectTagServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/PromptServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/PromptServiceAsyncImpl.kt index 9ab510a4..0c56cbf4 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/PromptServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/PromptServiceAsyncImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepareAsync -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.Prompt import com.braintrustdata.api.models.PromptCreateParams import com.braintrustdata.api.models.PromptDeleteParams @@ -79,7 +79,7 @@ class PromptServiceAsyncImpl internal constructor(private val clientOptions: Cli class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : PromptServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/RoleServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/RoleServiceAsyncImpl.kt index 17f4fe44..23ef1703 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/RoleServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/RoleServiceAsyncImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepareAsync -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.Role import com.braintrustdata.api.models.RoleCreateParams import com.braintrustdata.api.models.RoleDeleteParams @@ -79,7 +79,7 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : RoleServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsyncImpl.kt index 4d4bbb6f..c3699b95 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsyncImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepareAsync -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.SpanIFrame import com.braintrustdata.api.models.SpanIframeCreateParams import com.braintrustdata.api.models.SpanIframeDeleteParams @@ -79,7 +79,7 @@ class SpanIframeServiceAsyncImpl internal constructor(private val clientOptions: class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : SpanIframeServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/TopLevelServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/TopLevelServiceAsyncImpl.kt index efc7d4ce..26749e99 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/TopLevelServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/TopLevelServiceAsyncImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.stringHandler @@ -13,7 +14,6 @@ import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepareAsync -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.TopLevelHelloWorldParams import java.util.concurrent.CompletableFuture @@ -36,7 +36,7 @@ class TopLevelServiceAsyncImpl internal constructor(private val clientOptions: C class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : TopLevelServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val helloWorldHandler: Handler = stringHandler().withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/UserServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/UserServiceAsyncImpl.kt index 3537d101..acd4a367 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/UserServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/UserServiceAsyncImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -13,7 +14,6 @@ import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepareAsync -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.User import com.braintrustdata.api.models.UserListPageAsync import com.braintrustdata.api.models.UserListParams @@ -46,7 +46,7 @@ class UserServiceAsyncImpl internal constructor(private val clientOptions: Clien class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : UserServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ViewServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ViewServiceAsyncImpl.kt index 9af1e4de..7e6818fd 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ViewServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ViewServiceAsyncImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepareAsync -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.View import com.braintrustdata.api.models.ViewCreateParams import com.braintrustdata.api.models.ViewDeleteParams @@ -79,7 +79,7 @@ class ViewServiceAsyncImpl internal constructor(private val clientOptions: Clien class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ViewServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/organizations/MemberServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/organizations/MemberServiceAsyncImpl.kt index ac1cca4a..40d22d7b 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/organizations/MemberServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/organizations/MemberServiceAsyncImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.async.organizations import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepareAsync -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.OrganizationMemberUpdateParams import com.braintrustdata.api.models.PatchOrganizationMembersOutput import java.util.concurrent.CompletableFuture @@ -38,7 +38,7 @@ class MemberServiceAsyncImpl internal constructor(private val clientOptions: Cli class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : MemberServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/projects/LogServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/projects/LogServiceAsyncImpl.kt index 61d2e6a4..477e9056 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/projects/LogServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/projects/LogServiceAsyncImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.async.projects import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepareAsync -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.FeedbackResponseSchema import com.braintrustdata.api.models.FetchProjectLogsEventsResponse import com.braintrustdata.api.models.InsertEventsResponse @@ -64,7 +64,7 @@ class LogServiceAsyncImpl internal constructor(private val clientOptions: Client class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : LogServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val feedbackHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AclServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AclServiceImpl.kt index 2d0f7e46..919a26cf 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AclServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AclServiceImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepare -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.Acl import com.braintrustdata.api.models.AclBatchUpdateParams import com.braintrustdata.api.models.AclBatchUpdateResponse @@ -66,7 +66,7 @@ class AclServiceImpl internal constructor(private val clientOptions: ClientOptio class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : AclService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AiSecretServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AiSecretServiceImpl.kt index 9f45ea20..8e88a4ea 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AiSecretServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AiSecretServiceImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepare -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.AISecret import com.braintrustdata.api.models.AiSecretCreateParams import com.braintrustdata.api.models.AiSecretDeleteParams @@ -74,7 +74,7 @@ class AiSecretServiceImpl internal constructor(private val clientOptions: Client class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : AiSecretService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ApiKeyServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ApiKeyServiceImpl.kt index 9046ebc9..81057230 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ApiKeyServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ApiKeyServiceImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepare -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.ApiKey import com.braintrustdata.api.models.ApiKeyCreateParams import com.braintrustdata.api.models.ApiKeyDeleteParams @@ -54,7 +54,7 @@ class ApiKeyServiceImpl internal constructor(private val clientOptions: ClientOp class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ApiKeyService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/DatasetServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/DatasetServiceImpl.kt index f0ff8a15..093ad4fa 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/DatasetServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/DatasetServiceImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepare -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.Dataset import com.braintrustdata.api.models.DatasetCreateParams import com.braintrustdata.api.models.DatasetDeleteParams @@ -99,7 +99,7 @@ class DatasetServiceImpl internal constructor(private val clientOptions: ClientO class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : DatasetService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EnvVarServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EnvVarServiceImpl.kt index a8a07079..042d24b9 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EnvVarServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EnvVarServiceImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepare -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.EnvVar import com.braintrustdata.api.models.EnvVarCreateParams import com.braintrustdata.api.models.EnvVarDeleteParams @@ -63,7 +63,7 @@ class EnvVarServiceImpl internal constructor(private val clientOptions: ClientOp class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : EnvVarService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EvalServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EvalServiceImpl.kt index e761eba5..c590863e 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EvalServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EvalServiceImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepare -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.EvalCreateParams import com.braintrustdata.api.models.SummarizeExperimentResponse @@ -36,7 +36,7 @@ class EvalServiceImpl internal constructor(private val clientOptions: ClientOpti class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : EvalService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ExperimentServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ExperimentServiceImpl.kt index a07314c5..a17af091 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ExperimentServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ExperimentServiceImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepare -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.Experiment import com.braintrustdata.api.models.ExperimentCreateParams import com.braintrustdata.api.models.ExperimentDeleteParams @@ -114,7 +114,7 @@ class ExperimentServiceImpl internal constructor(private val clientOptions: Clie class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ExperimentService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceImpl.kt index e7409dd2..fb56d1bd 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepare -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.Function import com.braintrustdata.api.models.FunctionCreateParams import com.braintrustdata.api.models.FunctionDeleteParams @@ -76,7 +76,7 @@ class FunctionServiceImpl internal constructor(private val clientOptions: Client class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : FunctionService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/GroupServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/GroupServiceImpl.kt index 24e56e0f..4b13b23e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/GroupServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/GroupServiceImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepare -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.Group import com.braintrustdata.api.models.GroupCreateParams import com.braintrustdata.api.models.GroupDeleteParams @@ -60,7 +60,7 @@ class GroupServiceImpl internal constructor(private val clientOptions: ClientOpt class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : GroupService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/OrganizationServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/OrganizationServiceImpl.kt index 8171e93b..dae0721d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/OrganizationServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/OrganizationServiceImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepare -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.Organization import com.braintrustdata.api.models.OrganizationDeleteParams import com.braintrustdata.api.models.OrganizationListPage @@ -68,7 +68,7 @@ class OrganizationServiceImpl internal constructor(private val clientOptions: Cl class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : OrganizationService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val members: MemberService.WithRawResponse by lazy { MemberServiceImpl.WithRawResponseImpl(clientOptions) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreServiceImpl.kt index 43ad2558..6e7f231e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreServiceImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepare -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.ProjectScore import com.braintrustdata.api.models.ProjectScoreCreateParams import com.braintrustdata.api.models.ProjectScoreDeleteParams @@ -78,7 +78,7 @@ class ProjectScoreServiceImpl internal constructor(private val clientOptions: Cl class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ProjectScoreService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectServiceImpl.kt index 47d5b824..9ce11aad 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectServiceImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepare -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.Project import com.braintrustdata.api.models.ProjectCreateParams import com.braintrustdata.api.models.ProjectDeleteParams @@ -61,7 +61,7 @@ class ProjectServiceImpl internal constructor(private val clientOptions: ClientO class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ProjectService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val logs: LogService.WithRawResponse by lazy { LogServiceImpl.WithRawResponseImpl(clientOptions) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectTagServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectTagServiceImpl.kt index 73b857af..aab91cf9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectTagServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectTagServiceImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepare -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.ProjectTag import com.braintrustdata.api.models.ProjectTagCreateParams import com.braintrustdata.api.models.ProjectTagDeleteParams @@ -78,7 +78,7 @@ class ProjectTagServiceImpl internal constructor(private val clientOptions: Clie class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ProjectTagService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/PromptServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/PromptServiceImpl.kt index 8ceca7ba..e1d9fc74 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/PromptServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/PromptServiceImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepare -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.Prompt import com.braintrustdata.api.models.PromptCreateParams import com.braintrustdata.api.models.PromptDeleteParams @@ -60,7 +60,7 @@ class PromptServiceImpl internal constructor(private val clientOptions: ClientOp class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : PromptService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/RoleServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/RoleServiceImpl.kt index 4c9f75ec..b4be1645 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/RoleServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/RoleServiceImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepare -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.Role import com.braintrustdata.api.models.RoleCreateParams import com.braintrustdata.api.models.RoleDeleteParams @@ -59,7 +59,7 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : RoleService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/SpanIframeServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/SpanIframeServiceImpl.kt index ac7a0da5..51cc3e3a 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/SpanIframeServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/SpanIframeServiceImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepare -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.SpanIFrame import com.braintrustdata.api.models.SpanIframeCreateParams import com.braintrustdata.api.models.SpanIframeDeleteParams @@ -78,7 +78,7 @@ class SpanIframeServiceImpl internal constructor(private val clientOptions: Clie class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : SpanIframeService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/TopLevelServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/TopLevelServiceImpl.kt index 2bee0c27..44401cd1 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/TopLevelServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/TopLevelServiceImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.stringHandler @@ -13,7 +14,6 @@ import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepare -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.TopLevelHelloWorldParams class TopLevelServiceImpl internal constructor(private val clientOptions: ClientOptions) : @@ -35,7 +35,7 @@ class TopLevelServiceImpl internal constructor(private val clientOptions: Client class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : TopLevelService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val helloWorldHandler: Handler = stringHandler().withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/UserServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/UserServiceImpl.kt index 6ce8ea6d..821373cd 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/UserServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/UserServiceImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -13,7 +14,6 @@ import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepare -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.User import com.braintrustdata.api.models.UserListPage import com.braintrustdata.api.models.UserListParams @@ -38,7 +38,7 @@ class UserServiceImpl internal constructor(private val clientOptions: ClientOpti class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : UserService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ViewServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ViewServiceImpl.kt index 1facbf97..f1792d0b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ViewServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ViewServiceImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepare -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.View import com.braintrustdata.api.models.ViewCreateParams import com.braintrustdata.api.models.ViewDeleteParams @@ -59,7 +59,7 @@ class ViewServiceImpl internal constructor(private val clientOptions: ClientOpti class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ViewService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/organizations/MemberServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/organizations/MemberServiceImpl.kt index ffd783ac..df56e162 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/organizations/MemberServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/organizations/MemberServiceImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.blocking.organizations import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepare -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.OrganizationMemberUpdateParams import com.braintrustdata.api.models.PatchOrganizationMembersOutput @@ -37,7 +37,7 @@ class MemberServiceImpl internal constructor(private val clientOptions: ClientOp class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : MemberService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/projects/LogServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/projects/LogServiceImpl.kt index 2e2f1592..ec5204b8 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/projects/LogServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/projects/LogServiceImpl.kt @@ -3,6 +3,7 @@ package com.braintrustdata.api.services.blocking.projects import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler @@ -14,7 +15,6 @@ import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepare -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.models.FeedbackResponseSchema import com.braintrustdata.api.models.FetchProjectLogsEventsResponse import com.braintrustdata.api.models.InsertEventsResponse @@ -62,7 +62,7 @@ class LogServiceImpl internal constructor(private val clientOptions: ClientOptio class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : LogService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) private val feedbackHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/ErrorHandlingTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/ErrorHandlingTest.kt index 2716a7ab..56b5baef 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/ErrorHandlingTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/ErrorHandlingTest.kt @@ -8,7 +8,6 @@ import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.jsonMapper import com.braintrustdata.api.errors.BadRequestException -import com.braintrustdata.api.errors.BraintrustError import com.braintrustdata.api.errors.BraintrustException import com.braintrustdata.api.errors.InternalServerException import com.braintrustdata.api.errors.NotFoundException @@ -35,12 +34,9 @@ internal class ErrorHandlingTest { companion object { - private val ERROR: BraintrustError = - BraintrustError.builder() - .putAdditionalProperty("errorProperty", JsonValue.from("42")) - .build() + private val ERROR_JSON: JsonValue = JsonValue.from(mapOf("errorProperty" to "42")) - private val ERROR_JSON: ByteArray = jsonMapper().writeValueAsBytes(ERROR) + private val ERROR_JSON_BYTES: ByteArray = jsonMapper().writeValueAsBytes(ERROR_JSON) private const val HEADER_NAME: String = "Error-Header" @@ -65,7 +61,9 @@ internal class ErrorHandlingTest { val projectService = client.projects() stubFor( post(anyUrl()) - .willReturn(status(400).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON)) + .willReturn( + status(400).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + ) ) val e = @@ -76,8 +74,8 @@ internal class ErrorHandlingTest { } assertThat(e.statusCode()).isEqualTo(400) - assertThat(e.error()).isEqualTo(ERROR) assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) + assertThat(e.body()).isEqualTo(ERROR_JSON) } @Test @@ -85,7 +83,9 @@ internal class ErrorHandlingTest { val projectService = client.projects() stubFor( post(anyUrl()) - .willReturn(status(401).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON)) + .willReturn( + status(401).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + ) ) val e = @@ -96,8 +96,8 @@ internal class ErrorHandlingTest { } assertThat(e.statusCode()).isEqualTo(401) - assertThat(e.error()).isEqualTo(ERROR) assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) + assertThat(e.body()).isEqualTo(ERROR_JSON) } @Test @@ -105,7 +105,9 @@ internal class ErrorHandlingTest { val projectService = client.projects() stubFor( post(anyUrl()) - .willReturn(status(403).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON)) + .willReturn( + status(403).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + ) ) val e = @@ -116,8 +118,8 @@ internal class ErrorHandlingTest { } assertThat(e.statusCode()).isEqualTo(403) - assertThat(e.error()).isEqualTo(ERROR) assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) + assertThat(e.body()).isEqualTo(ERROR_JSON) } @Test @@ -125,7 +127,9 @@ internal class ErrorHandlingTest { val projectService = client.projects() stubFor( post(anyUrl()) - .willReturn(status(404).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON)) + .willReturn( + status(404).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + ) ) val e = @@ -136,8 +140,8 @@ internal class ErrorHandlingTest { } assertThat(e.statusCode()).isEqualTo(404) - assertThat(e.error()).isEqualTo(ERROR) assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) + assertThat(e.body()).isEqualTo(ERROR_JSON) } @Test @@ -145,7 +149,9 @@ internal class ErrorHandlingTest { val projectService = client.projects() stubFor( post(anyUrl()) - .willReturn(status(422).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON)) + .willReturn( + status(422).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + ) ) val e = @@ -156,8 +162,8 @@ internal class ErrorHandlingTest { } assertThat(e.statusCode()).isEqualTo(422) - assertThat(e.error()).isEqualTo(ERROR) assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) + assertThat(e.body()).isEqualTo(ERROR_JSON) } @Test @@ -165,7 +171,9 @@ internal class ErrorHandlingTest { val projectService = client.projects() stubFor( post(anyUrl()) - .willReturn(status(429).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON)) + .willReturn( + status(429).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + ) ) val e = @@ -176,8 +184,8 @@ internal class ErrorHandlingTest { } assertThat(e.statusCode()).isEqualTo(429) - assertThat(e.error()).isEqualTo(ERROR) assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) + assertThat(e.body()).isEqualTo(ERROR_JSON) } @Test @@ -185,7 +193,9 @@ internal class ErrorHandlingTest { val projectService = client.projects() stubFor( post(anyUrl()) - .willReturn(status(500).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON)) + .willReturn( + status(500).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + ) ) val e = @@ -196,8 +206,8 @@ internal class ErrorHandlingTest { } assertThat(e.statusCode()).isEqualTo(500) - assertThat(e.error()).isEqualTo(ERROR) assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) + assertThat(e.body()).isEqualTo(ERROR_JSON) } @Test @@ -205,7 +215,9 @@ internal class ErrorHandlingTest { val projectService = client.projects() stubFor( post(anyUrl()) - .willReturn(status(999).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON)) + .willReturn( + status(999).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + ) ) val e = @@ -216,8 +228,8 @@ internal class ErrorHandlingTest { } assertThat(e.statusCode()).isEqualTo(999) - assertThat(e.error()).isEqualTo(ERROR) assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) + assertThat(e.body()).isEqualTo(ERROR_JSON) } @Test From 6d403189bb05ab3934586907f2cb8f093e65c805 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 21 Mar 2025 07:02:08 +0000 Subject: [PATCH 08/42] docs: refine comments on multipart params (#165) chore(internal): make multipart assertions more robust chore(internal): remove unnecessary `assertNotNull` calls --- .../api/core/http/HttpRequestBodies.kt | 13 ++++++------- .../api/models/AclBatchUpdateParamsTest.kt | 4 ---- .../api/models/AclCreateParamsTest.kt | 3 --- .../api/models/AclFindAndDeleteParamsTest.kt | 3 --- .../api/models/AiSecretCreateParamsTest.kt | 3 --- .../api/models/AiSecretFindAndDeleteParamsTest.kt | 3 --- .../api/models/AiSecretReplaceParamsTest.kt | 3 --- .../api/models/AiSecretUpdateParamsTest.kt | 4 ---- .../api/models/ApiKeyCreateParamsTest.kt | 3 --- .../api/models/DatasetCreateParamsTest.kt | 3 --- .../api/models/DatasetFeedbackParamsTest.kt | 3 --- .../api/models/DatasetFetchPostParamsTest.kt | 4 ---- .../api/models/DatasetInsertParamsTest.kt | 3 --- .../api/models/DatasetUpdateParamsTest.kt | 4 ---- .../api/models/EnvVarCreateParamsTest.kt | 3 --- .../api/models/EnvVarReplaceParamsTest.kt | 3 --- .../api/models/EnvVarUpdateParamsTest.kt | 3 --- .../api/models/EvalCreateParamsTest.kt | 3 --- .../api/models/ExperimentCreateParamsTest.kt | 3 --- .../api/models/ExperimentFeedbackParamsTest.kt | 3 --- .../api/models/ExperimentFetchPostParamsTest.kt | 4 ---- .../api/models/ExperimentInsertParamsTest.kt | 3 --- .../api/models/ExperimentUpdateParamsTest.kt | 4 ---- .../api/models/FunctionCreateParamsTest.kt | 3 --- .../api/models/FunctionInvokeParamsTest.kt | 4 ---- .../api/models/FunctionReplaceParamsTest.kt | 3 --- .../api/models/FunctionUpdateParamsTest.kt | 4 ---- .../api/models/GroupCreateParamsTest.kt | 3 --- .../api/models/GroupReplaceParamsTest.kt | 3 --- .../api/models/GroupUpdateParamsTest.kt | 4 ---- .../models/OrganizationMemberUpdateParamsTest.kt | 4 ---- .../api/models/OrganizationUpdateParamsTest.kt | 4 ---- .../api/models/ProjectCreateParamsTest.kt | 3 --- .../api/models/ProjectLogFeedbackParamsTest.kt | 3 --- .../api/models/ProjectLogFetchPostParamsTest.kt | 4 ---- .../api/models/ProjectLogInsertParamsTest.kt | 3 --- .../api/models/ProjectScoreCreateParamsTest.kt | 3 --- .../api/models/ProjectScoreReplaceParamsTest.kt | 3 --- .../api/models/ProjectScoreUpdateParamsTest.kt | 4 ---- .../api/models/ProjectTagCreateParamsTest.kt | 3 --- .../api/models/ProjectTagReplaceParamsTest.kt | 3 --- .../api/models/ProjectTagUpdateParamsTest.kt | 4 ---- .../api/models/ProjectUpdateParamsTest.kt | 4 ---- .../api/models/PromptCreateParamsTest.kt | 3 --- .../api/models/PromptReplaceParamsTest.kt | 3 --- .../api/models/PromptUpdateParamsTest.kt | 4 ---- .../api/models/RoleCreateParamsTest.kt | 3 --- .../api/models/RoleReplaceParamsTest.kt | 3 --- .../api/models/RoleUpdateParamsTest.kt | 4 ---- .../api/models/SpanIframeCreateParamsTest.kt | 3 --- .../api/models/SpanIframeReplaceParamsTest.kt | 3 --- .../api/models/SpanIframeUpdateParamsTest.kt | 4 ---- .../api/models/ViewCreateParamsTest.kt | 3 --- .../api/models/ViewDeleteParamsTest.kt | 2 -- .../api/models/ViewReplaceParamsTest.kt | 3 --- .../api/models/ViewUpdateParamsTest.kt | 3 --- 56 files changed, 6 insertions(+), 189 deletions(-) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/HttpRequestBodies.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/HttpRequestBodies.kt index bb5b61ab..2ab71012 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/HttpRequestBodies.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/HttpRequestBodies.kt @@ -9,7 +9,6 @@ import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.json.JsonMapper import com.fasterxml.jackson.databind.node.JsonNodeType -import java.io.ByteArrayInputStream import java.io.InputStream import java.io.OutputStream import kotlin.jvm.optionals.getOrNull @@ -74,12 +73,12 @@ internal fun multipartFormData( when (node.nodeType) { JsonNodeType.MISSING, JsonNodeType.NULL -> emptySequence() - JsonNodeType.BINARY -> sequenceOf(name to ByteArrayInputStream(node.binaryValue())) - JsonNodeType.STRING -> sequenceOf(name to node.textValue().toInputStream()) + JsonNodeType.BINARY -> sequenceOf(name to node.binaryValue().inputStream()) + JsonNodeType.STRING -> sequenceOf(name to node.textValue().inputStream()) JsonNodeType.BOOLEAN -> - sequenceOf(name to node.booleanValue().toString().toInputStream()) + sequenceOf(name to node.booleanValue().toString().inputStream()) JsonNodeType.NUMBER -> - sequenceOf(name to node.numberValue().toString().toInputStream()) + sequenceOf(name to node.numberValue().toString().inputStream()) JsonNodeType.ARRAY -> sequenceOf( name to @@ -104,7 +103,7 @@ internal fun multipartFormData( } } .joinToString(",") - .toInputStream() + .inputStream() ) JsonNodeType.OBJECT -> node.fields().asSequence().flatMap { (key, value) -> @@ -117,7 +116,7 @@ internal fun multipartFormData( ) } - private fun String.toInputStream(): InputStream = ByteArrayInputStream(toByteArray()) + private fun String.inputStream(): InputStream = toByteArray().inputStream() override fun writeTo(outputStream: OutputStream) = entity.writeTo(outputStream) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclBatchUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclBatchUpdateParamsTest.kt index fd9775ea..c59b1e7a 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclBatchUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclBatchUpdateParamsTest.kt @@ -3,7 +3,6 @@ package com.braintrustdata.api.models import kotlin.jvm.optionals.getOrNull -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -67,7 +66,6 @@ internal class AclBatchUpdateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.addAcls().getOrNull()) .containsExactly( AclBatchUpdateParams.AddAcl.builder() @@ -99,7 +97,5 @@ internal class AclBatchUpdateParamsTest { val params = AclBatchUpdateParams.builder().build() val body = params._body() - - assertNotNull(body) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclCreateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclCreateParamsTest.kt index 20eb299f..8076e142 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclCreateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclCreateParamsTest.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -36,7 +35,6 @@ internal class AclCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.objectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.objectType()).isEqualTo(AclObjectType.ORGANIZATION) assertThat(body.groupId()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -56,7 +54,6 @@ internal class AclCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.objectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.objectType()).isEqualTo(AclObjectType.ORGANIZATION) } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParamsTest.kt index d6b03177..3185f02a 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParamsTest.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -36,7 +35,6 @@ internal class AclFindAndDeleteParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.objectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.objectType()).isEqualTo(AclObjectType.ORGANIZATION) assertThat(body.groupId()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -56,7 +54,6 @@ internal class AclFindAndDeleteParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.objectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.objectType()).isEqualTo(AclObjectType.ORGANIZATION) } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretCreateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretCreateParamsTest.kt index d91d0d19..a3115935 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretCreateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretCreateParamsTest.kt @@ -3,7 +3,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -41,7 +40,6 @@ internal class AiSecretCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") assertThat(body.metadata()) .contains( @@ -60,7 +58,6 @@ internal class AiSecretCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParamsTest.kt index d7365a0b..7e72a927 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParamsTest.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -19,7 +18,6 @@ internal class AiSecretFindAndDeleteParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") assertThat(body.orgName()).contains("org_name") } @@ -30,7 +28,6 @@ internal class AiSecretFindAndDeleteParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretReplaceParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretReplaceParamsTest.kt index cde09c24..4f3b98f1 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretReplaceParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretReplaceParamsTest.kt @@ -3,7 +3,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -41,7 +40,6 @@ internal class AiSecretReplaceParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") assertThat(body.metadata()) .contains( @@ -60,7 +58,6 @@ internal class AiSecretReplaceParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretUpdateParamsTest.kt index 2708f3b5..27e6e879 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretUpdateParamsTest.kt @@ -3,7 +3,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -53,7 +52,6 @@ internal class AiSecretUpdateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.metadata()) .contains( AiSecretUpdateParams.Metadata.builder() @@ -73,7 +71,5 @@ internal class AiSecretUpdateParamsTest { .build() val body = params._body() - - assertNotNull(body) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ApiKeyCreateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ApiKeyCreateParamsTest.kt index 315dc13b..ef31b0d6 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ApiKeyCreateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ApiKeyCreateParamsTest.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -19,7 +18,6 @@ internal class ApiKeyCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") assertThat(body.orgName()).contains("org_name") } @@ -30,7 +28,6 @@ internal class ApiKeyCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetCreateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetCreateParamsTest.kt index e9bd56e1..117b3591 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetCreateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetCreateParamsTest.kt @@ -3,7 +3,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -39,7 +38,6 @@ internal class DatasetCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("x") assertThat(body.projectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.description()).contains("description") @@ -61,7 +59,6 @@ internal class DatasetCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("x") assertThat(body.projectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetFeedbackParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetFeedbackParamsTest.kt index f6492260..383af384 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetFeedbackParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetFeedbackParamsTest.kt @@ -3,7 +3,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -64,7 +63,6 @@ internal class DatasetFeedbackParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.feedback()) .containsExactly( FeedbackDatasetItem.builder() @@ -91,7 +89,6 @@ internal class DatasetFeedbackParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.feedback()).containsExactly(FeedbackDatasetItem.builder().id("id").build()) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetFetchPostParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetFetchPostParamsTest.kt index e2b5f2d9..e3e09e9b 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetFetchPostParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetFetchPostParamsTest.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -46,7 +45,6 @@ internal class DatasetFetchPostParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.cursor()).contains("cursor") assertThat(body.limit()).contains(0L) assertThat(body.maxRootSpanId()).contains("max_root_span_id") @@ -62,7 +60,5 @@ internal class DatasetFetchPostParamsTest { .build() val body = params._body() - - assertNotNull(body) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetInsertParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetInsertParamsTest.kt index 901f6f82..09847227 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetInsertParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetInsertParamsTest.kt @@ -4,7 +4,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import java.time.OffsetDateTime -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -91,7 +90,6 @@ internal class DatasetInsertParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.events()) .containsExactly( InsertDatasetEvent.builder() @@ -131,7 +129,6 @@ internal class DatasetInsertParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.events()).containsExactly(InsertDatasetEvent.builder().build()) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetUpdateParamsTest.kt index c90a33a0..daee439a 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetUpdateParamsTest.kt @@ -3,7 +3,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -49,7 +48,6 @@ internal class DatasetUpdateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.description()).contains("description") assertThat(body.metadata()) .contains( @@ -66,7 +64,5 @@ internal class DatasetUpdateParamsTest { DatasetUpdateParams.builder().datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() val body = params._body() - - assertNotNull(body) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarCreateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarCreateParamsTest.kt index 1af40d88..fbb18ad2 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarCreateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarCreateParamsTest.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -30,7 +29,6 @@ internal class EnvVarCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") assertThat(body.objectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.objectType()).isEqualTo(EnvVarCreateParams.ObjectType.ORGANIZATION) @@ -48,7 +46,6 @@ internal class EnvVarCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") assertThat(body.objectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.objectType()).isEqualTo(EnvVarCreateParams.ObjectType.ORGANIZATION) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarReplaceParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarReplaceParamsTest.kt index 74d5e35f..bb097933 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarReplaceParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarReplaceParamsTest.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -30,7 +29,6 @@ internal class EnvVarReplaceParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") assertThat(body.objectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.objectType()).isEqualTo(EnvVarReplaceParams.ObjectType.ORGANIZATION) @@ -48,7 +46,6 @@ internal class EnvVarReplaceParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") assertThat(body.objectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.objectType()).isEqualTo(EnvVarReplaceParams.ObjectType.ORGANIZATION) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarUpdateParamsTest.kt index 4198a5c5..ec4c0edc 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarUpdateParamsTest.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -41,7 +40,6 @@ internal class EnvVarUpdateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") assertThat(body.value()).contains("value") } @@ -56,7 +54,6 @@ internal class EnvVarUpdateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EvalCreateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EvalCreateParamsTest.kt index cf8b33be..99ba29a1 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EvalCreateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EvalCreateParamsTest.kt @@ -3,7 +3,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -173,7 +172,6 @@ internal class EvalCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.data()) .isEqualTo( EvalCreateParams.Data.ofDatasetId( @@ -281,7 +279,6 @@ internal class EvalCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.data()) .isEqualTo( EvalCreateParams.Data.ofDatasetId( diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentCreateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentCreateParamsTest.kt index d7f74f35..9c672670 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentCreateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentCreateParamsTest.kt @@ -3,7 +3,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -75,7 +74,6 @@ internal class ExperimentCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.projectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.baseExpId()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.datasetId()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -115,7 +113,6 @@ internal class ExperimentCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.projectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParamsTest.kt index f7220d83..ed20850d 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParamsTest.kt @@ -3,7 +3,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -76,7 +75,6 @@ internal class ExperimentFeedbackParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.feedback()) .containsExactly( FeedbackExperimentItem.builder() @@ -109,7 +107,6 @@ internal class ExperimentFeedbackParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.feedback()) .containsExactly(FeedbackExperimentItem.builder().id("id").build()) } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParamsTest.kt index 29230582..b1a4e806 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParamsTest.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -46,7 +45,6 @@ internal class ExperimentFetchPostParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.cursor()).contains("cursor") assertThat(body.limit()).contains(0L) assertThat(body.maxRootSpanId()).contains("max_root_span_id") @@ -62,7 +60,5 @@ internal class ExperimentFetchPostParamsTest { .build() val body = params._body() - - assertNotNull(body) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentInsertParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentInsertParamsTest.kt index be527a66..105b8225 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentInsertParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentInsertParamsTest.kt @@ -4,7 +4,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import java.time.OffsetDateTime -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -149,7 +148,6 @@ internal class ExperimentInsertParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.events()) .containsExactly( InsertExperimentEvent.builder() @@ -218,7 +216,6 @@ internal class ExperimentInsertParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.events()).containsExactly(InsertExperimentEvent.builder().build()) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentUpdateParamsTest.kt index 379cb233..214f8988 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentUpdateParamsTest.kt @@ -3,7 +3,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -85,7 +84,6 @@ internal class ExperimentUpdateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.baseExpId()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.datasetId()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.datasetVersion()).contains("dataset_version") @@ -122,7 +120,5 @@ internal class ExperimentUpdateParamsTest { .build() val body = params._body() - - assertNotNull(body) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionCreateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionCreateParamsTest.kt index 45b97b27..1c191402 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionCreateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionCreateParamsTest.kt @@ -4,7 +4,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import kotlin.jvm.optionals.getOrNull -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -231,7 +230,6 @@ internal class FunctionCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.functionData()) .isEqualTo( FunctionCreateParams.FunctionData.ofPrompt( @@ -359,7 +357,6 @@ internal class FunctionCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.functionData()) .isEqualTo( FunctionCreateParams.FunctionData.ofPrompt( diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionInvokeParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionInvokeParamsTest.kt index 40aeb417..5709c972 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionInvokeParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionInvokeParamsTest.kt @@ -4,7 +4,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import kotlin.jvm.optionals.getOrNull -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -112,7 +111,6 @@ internal class FunctionInvokeParamsTest { val body = params._body() - assertNotNull(body) assertThat(body._expected()).isEqualTo(JsonValue.from(mapOf())) assertThat(body._input()).isEqualTo(JsonValue.from(mapOf())) assertThat(body.messages().getOrNull()) @@ -167,7 +165,5 @@ internal class FunctionInvokeParamsTest { .build() val body = params._body() - - assertNotNull(body) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionReplaceParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionReplaceParamsTest.kt index af90f34c..3e43d5eb 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionReplaceParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionReplaceParamsTest.kt @@ -4,7 +4,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import kotlin.jvm.optionals.getOrNull -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -231,7 +230,6 @@ internal class FunctionReplaceParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.functionData()) .isEqualTo( FunctionReplaceParams.FunctionData.ofPrompt( @@ -359,7 +357,6 @@ internal class FunctionReplaceParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.functionData()) .isEqualTo( FunctionReplaceParams.FunctionData.ofPrompt( diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionUpdateParamsTest.kt index 94a7bbd5..efa128b9 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionUpdateParamsTest.kt @@ -4,7 +4,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import kotlin.jvm.optionals.getOrNull -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -213,7 +212,6 @@ internal class FunctionUpdateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.description()).contains("description") assertThat(body.functionData()) .contains( @@ -315,7 +313,5 @@ internal class FunctionUpdateParamsTest { .build() val body = params._body() - - assertNotNull(body) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupCreateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupCreateParamsTest.kt index 9fabfeab..f050afce 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupCreateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupCreateParamsTest.kt @@ -3,7 +3,6 @@ package com.braintrustdata.api.models import kotlin.jvm.optionals.getOrNull -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -33,7 +32,6 @@ internal class GroupCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("x") assertThat(body.description()).contains("description") assertThat(body.memberGroups().getOrNull()) @@ -49,7 +47,6 @@ internal class GroupCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("x") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupReplaceParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupReplaceParamsTest.kt index 4b1a8be3..380f91aa 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupReplaceParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupReplaceParamsTest.kt @@ -3,7 +3,6 @@ package com.braintrustdata.api.models import kotlin.jvm.optionals.getOrNull -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -33,7 +32,6 @@ internal class GroupReplaceParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("x") assertThat(body.description()).contains("description") assertThat(body.memberGroups().getOrNull()) @@ -49,7 +47,6 @@ internal class GroupReplaceParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("x") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupUpdateParamsTest.kt index 62745599..f5ea0ee6 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupUpdateParamsTest.kt @@ -3,7 +3,6 @@ package com.braintrustdata.api.models import kotlin.jvm.optionals.getOrNull -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -47,7 +46,6 @@ internal class GroupUpdateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.addMemberGroups().getOrNull()) .containsExactly("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.addMemberUsers().getOrNull()) @@ -66,7 +64,5 @@ internal class GroupUpdateParamsTest { GroupUpdateParams.builder().groupId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() val body = params._body() - - assertNotNull(body) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationMemberUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationMemberUpdateParamsTest.kt index a9430430..bc86325c 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationMemberUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationMemberUpdateParamsTest.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -60,7 +59,6 @@ internal class OrganizationMemberUpdateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.inviteUsers()) .contains( OrganizationMemberUpdateParams.InviteUsers.builder() @@ -89,7 +87,5 @@ internal class OrganizationMemberUpdateParamsTest { val params = OrganizationMemberUpdateParams.builder().build() val body = params._body() - - assertNotNull(body) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationUpdateParamsTest.kt index b36c421b..a66f513e 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationUpdateParamsTest.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -46,7 +45,6 @@ internal class OrganizationUpdateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.apiUrl()).contains("api_url") assertThat(body.isUniversalApi()).contains(true) assertThat(body.name()).contains("name") @@ -62,7 +60,5 @@ internal class OrganizationUpdateParamsTest { .build() val body = params._body() - - assertNotNull(body) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectCreateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectCreateParamsTest.kt index c9ffd874..8751112d 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectCreateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectCreateParamsTest.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -19,7 +18,6 @@ internal class ProjectCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("x") assertThat(body.orgName()).contains("org_name") } @@ -30,7 +28,6 @@ internal class ProjectCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("x") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParamsTest.kt index c6c6141e..59f797ac 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParamsTest.kt @@ -3,7 +3,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -76,7 +75,6 @@ internal class ProjectLogFeedbackParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.feedback()) .containsExactly( FeedbackProjectLogsItem.builder() @@ -109,7 +107,6 @@ internal class ProjectLogFeedbackParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.feedback()) .containsExactly(FeedbackProjectLogsItem.builder().id("id").build()) } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParamsTest.kt index ec1fbe5d..e6c1f8ff 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParamsTest.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -46,7 +45,6 @@ internal class ProjectLogFetchPostParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.cursor()).contains("cursor") assertThat(body.limit()).contains(0L) assertThat(body.maxRootSpanId()).contains("max_root_span_id") @@ -62,7 +60,5 @@ internal class ProjectLogFetchPostParamsTest { .build() val body = params._body() - - assertNotNull(body) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogInsertParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogInsertParamsTest.kt index 602502ea..1cf5e777 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogInsertParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogInsertParamsTest.kt @@ -4,7 +4,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import java.time.OffsetDateTime -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -149,7 +148,6 @@ internal class ProjectLogInsertParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.events()) .containsExactly( InsertProjectLogsEvent.builder() @@ -218,7 +216,6 @@ internal class ProjectLogInsertParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.events()).containsExactly(InsertProjectLogsEvent.builder().build()) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParamsTest.kt index af4c04c3..a192a789 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParamsTest.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -74,7 +73,6 @@ internal class ProjectScoreCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") assertThat(body.projectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.scoreType()).isEqualTo(ProjectScoreType.SLIDER) @@ -118,7 +116,6 @@ internal class ProjectScoreCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") assertThat(body.projectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.scoreType()).isEqualTo(ProjectScoreType.SLIDER) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParamsTest.kt index 50960ecf..b569d015 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParamsTest.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -74,7 +73,6 @@ internal class ProjectScoreReplaceParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") assertThat(body.projectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.scoreType()).isEqualTo(ProjectScoreType.SLIDER) @@ -118,7 +116,6 @@ internal class ProjectScoreReplaceParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") assertThat(body.projectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.scoreType()).isEqualTo(ProjectScoreType.SLIDER) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParamsTest.kt index fc675dff..1feddf2e 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParamsTest.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -86,7 +85,6 @@ internal class ProjectScoreUpdateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.categories()) .contains( ProjectScoreUpdateParams.Categories.ofCategorical( @@ -126,7 +124,5 @@ internal class ProjectScoreUpdateParamsTest { .build() val body = params._body() - - assertNotNull(body) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagCreateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagCreateParamsTest.kt index 221e1eb7..c738ab63 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagCreateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagCreateParamsTest.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -30,7 +29,6 @@ internal class ProjectTagCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") assertThat(body.projectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.color()).contains("color") @@ -47,7 +45,6 @@ internal class ProjectTagCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") assertThat(body.projectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagReplaceParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagReplaceParamsTest.kt index c3c2cb8c..39eae201 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagReplaceParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagReplaceParamsTest.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -30,7 +29,6 @@ internal class ProjectTagReplaceParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") assertThat(body.projectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.color()).contains("color") @@ -47,7 +45,6 @@ internal class ProjectTagReplaceParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") assertThat(body.projectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParamsTest.kt index a66f060e..beb3b668 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParamsTest.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -42,7 +41,6 @@ internal class ProjectTagUpdateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.color()).contains("color") assertThat(body.description()).contains("description") assertThat(body.name()).contains("name") @@ -56,7 +54,5 @@ internal class ProjectTagUpdateParamsTest { .build() val body = params._body() - - assertNotNull(body) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectUpdateParamsTest.kt index 17f26452..99b062a2 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectUpdateParamsTest.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -64,7 +63,6 @@ internal class ProjectUpdateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).contains("name") assertThat(body.settings()) .contains( @@ -89,7 +87,5 @@ internal class ProjectUpdateParamsTest { ProjectUpdateParams.builder().projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() val body = params._body() - - assertNotNull(body) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptCreateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptCreateParamsTest.kt index 357be90b..8013fd96 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptCreateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptCreateParamsTest.kt @@ -4,7 +4,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import kotlin.jvm.optionals.getOrNull -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -195,7 +194,6 @@ internal class PromptCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("x") assertThat(body.projectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.slug()).isEqualTo("x") @@ -295,7 +293,6 @@ internal class PromptCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("x") assertThat(body.projectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.slug()).isEqualTo("x") diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptReplaceParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptReplaceParamsTest.kt index 2d6a3afe..2b627b25 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptReplaceParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptReplaceParamsTest.kt @@ -4,7 +4,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import kotlin.jvm.optionals.getOrNull -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -195,7 +194,6 @@ internal class PromptReplaceParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("x") assertThat(body.projectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.slug()).isEqualTo("x") @@ -295,7 +293,6 @@ internal class PromptReplaceParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("x") assertThat(body.projectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.slug()).isEqualTo("x") diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptUpdateParamsTest.kt index fe47a21d..43dfac44 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptUpdateParamsTest.kt @@ -4,7 +4,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import kotlin.jvm.optionals.getOrNull -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -203,7 +202,6 @@ internal class PromptUpdateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.description()).contains("description") assertThat(body.name()).contains("name") assertThat(body.promptData()) @@ -296,7 +294,5 @@ internal class PromptUpdateParamsTest { PromptUpdateParams.builder().promptId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() val body = params._body() - - assertNotNull(body) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleCreateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleCreateParamsTest.kt index a88e6617..74b23cad 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleCreateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleCreateParamsTest.kt @@ -3,7 +3,6 @@ package com.braintrustdata.api.models import kotlin.jvm.optionals.getOrNull -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -43,7 +42,6 @@ internal class RoleCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("x") assertThat(body.description()).contains("description") assertThat(body.memberPermissions().getOrNull()) @@ -64,7 +62,6 @@ internal class RoleCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("x") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleReplaceParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleReplaceParamsTest.kt index 08ea1f4b..5b3ce5ce 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleReplaceParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleReplaceParamsTest.kt @@ -3,7 +3,6 @@ package com.braintrustdata.api.models import kotlin.jvm.optionals.getOrNull -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -43,7 +42,6 @@ internal class RoleReplaceParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("x") assertThat(body.description()).contains("description") assertThat(body.memberPermissions().getOrNull()) @@ -64,7 +62,6 @@ internal class RoleReplaceParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("x") } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleUpdateParamsTest.kt index aa80e9be..bfa8c9bf 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleUpdateParamsTest.kt @@ -3,7 +3,6 @@ package com.braintrustdata.api.models import kotlin.jvm.optionals.getOrNull -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -67,7 +66,6 @@ internal class RoleUpdateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.addMemberPermissions().getOrNull()) .containsExactly( RoleUpdateParams.AddMemberPermission.builder() @@ -96,7 +94,5 @@ internal class RoleUpdateParamsTest { RoleUpdateParams.builder().roleId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() val body = params._body() - - assertNotNull(body) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeCreateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeCreateParamsTest.kt index 16fcf240..b95ed798 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeCreateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeCreateParamsTest.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -32,7 +31,6 @@ internal class SpanIframeCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") assertThat(body.projectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.url()).isEqualTo("url") @@ -51,7 +49,6 @@ internal class SpanIframeCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") assertThat(body.projectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.url()).isEqualTo("url") diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeReplaceParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeReplaceParamsTest.kt index f641330c..959f5fa4 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeReplaceParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeReplaceParamsTest.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -32,7 +31,6 @@ internal class SpanIframeReplaceParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") assertThat(body.projectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.url()).isEqualTo("url") @@ -51,7 +49,6 @@ internal class SpanIframeReplaceParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") assertThat(body.projectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.url()).isEqualTo("url") diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParamsTest.kt index fdf02719..4a255d60 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParamsTest.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -44,7 +43,6 @@ internal class SpanIframeUpdateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.description()).contains("description") assertThat(body.name()).contains("name") assertThat(body.postMessage()).contains(true) @@ -59,7 +57,5 @@ internal class SpanIframeUpdateParamsTest { .build() val body = params._body() - - assertNotNull(body) } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewCreateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewCreateParamsTest.kt index c237c2ce..e86fd560 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewCreateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewCreateParamsTest.kt @@ -4,7 +4,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import java.time.OffsetDateTime -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -96,7 +95,6 @@ internal class ViewCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") assertThat(body.objectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.objectType()).isEqualTo(AclObjectType.ORGANIZATION) @@ -149,7 +147,6 @@ internal class ViewCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") assertThat(body.objectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.objectType()).isEqualTo(AclObjectType.ORGANIZATION) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDeleteParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDeleteParamsTest.kt index 6248015c..e6224941 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDeleteParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDeleteParamsTest.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -42,7 +41,6 @@ internal class ViewDeleteParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.objectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.objectType()).isEqualTo(AclObjectType.ORGANIZATION) } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewReplaceParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewReplaceParamsTest.kt index 6dd1cd82..7b715533 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewReplaceParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewReplaceParamsTest.kt @@ -4,7 +4,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import java.time.OffsetDateTime -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -96,7 +95,6 @@ internal class ViewReplaceParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") assertThat(body.objectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.objectType()).isEqualTo(AclObjectType.ORGANIZATION) @@ -149,7 +147,6 @@ internal class ViewReplaceParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.name()).isEqualTo("name") assertThat(body.objectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.objectType()).isEqualTo(AclObjectType.ORGANIZATION) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewUpdateParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewUpdateParamsTest.kt index 67aaa298..f2e0332c 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewUpdateParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewUpdateParamsTest.kt @@ -3,7 +3,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -109,7 +108,6 @@ internal class ViewUpdateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.objectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.objectType()).isEqualTo(AclObjectType.ORGANIZATION) assertThat(body.name()).contains("name") @@ -160,7 +158,6 @@ internal class ViewUpdateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.objectId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(body.objectType()).isEqualTo(AclObjectType.ORGANIZATION) } From 3ce1a023b3013ffeb9fa9651b42ef3ba5a11fc6e Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 22 Mar 2025 06:51:17 +0000 Subject: [PATCH 09/42] chore(internal): fix example formatting (#166) --- braintrust-java-example/build.gradle.kts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/braintrust-java-example/build.gradle.kts b/braintrust-java-example/build.gradle.kts index df9438d5..298fe690 100644 --- a/braintrust-java-example/build.gradle.kts +++ b/braintrust-java-example/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("java") + id("braintrust.java") application } @@ -11,10 +11,9 @@ dependencies { implementation(project(":braintrust-java")) } -java { +tasks.withType().configureEach { // Allow using more modern APIs, like `List.of` and `Map.of`, in examples. - sourceCompatibility = JavaVersion.VERSION_1_9 - targetCompatibility = JavaVersion.VERSION_1_9 + options.release.set(9) } application { From 03d8ca931ab7599f98cef22d0b43a39b0d002f65 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 22 Mar 2025 06:56:52 +0000 Subject: [PATCH 10/42] chore(internal): remove unnecessary import (#167) --- .../kotlin/com/braintrustdata/api/core/http/HttpResponse.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/HttpResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/HttpResponse.kt index 901b030b..dbfbe2cb 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/HttpResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/HttpResponse.kt @@ -1,7 +1,8 @@ +// File generated from our OpenAPI spec by Stainless. + package com.braintrustdata.api.core.http import java.io.InputStream -import java.lang.AutoCloseable interface HttpResponse : AutoCloseable { From 39e01a6fb2b29e1c8806ec27191cfef234b012d9 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 22 Mar 2025 07:25:02 +0000 Subject: [PATCH 11/42] docs: update readme exception docs (#168) --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 1ec03da4..1f4ba0c6 100644 --- a/README.md +++ b/README.md @@ -197,16 +197,16 @@ The SDK throws custom unchecked exception types: - [`BraintrustServiceException`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BraintrustServiceException.kt): Base class for HTTP errors. See this table for which exception subclass is thrown for each HTTP status code: - | Status | Exception | - | ------ | ------------------------------- | - | 400 | `BadRequestException` | - | 401 | `AuthenticationException` | - | 403 | `PermissionDeniedException` | - | 404 | `NotFoundException` | - | 422 | `UnprocessableEntityException` | - | 429 | `RateLimitException` | - | 5xx | `InternalServerException` | - | others | `UnexpectedStatusCodeException` | + | Status | Exception | + | ------ | -------------------------------------------------------------------------------------------------------------------------------------- | + | 400 | [`BadRequestException`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BadRequestException.kt) | + | 401 | [`UnauthorizedException`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/UnauthorizedException.kt) | + | 403 | [`PermissionDeniedException`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/PermissionDeniedException.kt) | + | 404 | [`NotFoundException`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/NotFoundException.kt) | + | 422 | [`UnprocessableEntityException`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/UnprocessableEntityException.kt) | + | 429 | [`RateLimitException`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/RateLimitException.kt) | + | 5xx | [`InternalServerException`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/InternalServerException.kt) | + | others | [`UnexpectedStatusCodeException`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/UnexpectedStatusCodeException.kt) | - [`BraintrustIoException`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BraintrustIoException.kt): I/O networking errors. From 4154acdf5be17f6b8c3ec26ccf5ca25b61c75404 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 22 Mar 2025 07:28:33 +0000 Subject: [PATCH 12/42] docs: minor readme tweak (#169) --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1f4ba0c6..f32eedab 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ -The Braintrust Java SDK provides convenient access to the Braintrust REST API from applications written in Java. +The Braintrust Java SDK provides convenient access to the [Braintrust REST API](https://www.braintrustdata.com/docs/api/spec) from applications written in Java. The Braintrust Java SDK is similar to the Braintrust Kotlin SDK but with minor differences that make it more ergonomic for use in Java, such as `Optional` instead of nullable values, `Stream` instead of `Sequence`, and `CompletableFuture` instead of suspend functions. @@ -33,9 +33,9 @@ implementation("com.braintrustdata.api:braintrust-java:0.8.0") ```xml - com.braintrustdata.api - braintrust-java - 0.8.0 + com.braintrustdata.api + braintrust-java + 0.8.0 ``` From 803e2917444885e37e3148499f875ef59824f3c2 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 26 Mar 2025 04:04:12 +0000 Subject: [PATCH 13/42] feat(client): support a lower jackson version (#170) feat(client): throw on incompatible jackson version --- .../client/okhttp/BraintrustOkHttpClient.kt | 11 + .../okhttp/BraintrustOkHttpClientAsync.kt | 11 + braintrust-java-core/build.gradle.kts | 13 + .../com/braintrustdata/api/core/Check.kt | 46 + .../braintrustdata/api/core/ClientOptions.kt | 14 + .../braintrustdata/api/core/ObjectMappers.kt | 54 +- .../com/braintrustdata/api/core/Values.kt | 20 +- .../api/core/handlers/JsonHandler.kt | 4 +- .../api/errors/BadRequestException.kt | 4 +- .../api/errors/NotFoundException.kt | 4 +- .../api/errors/PermissionDeniedException.kt | 4 +- .../api/errors/RateLimitException.kt | 4 +- .../api/errors/UnauthorizedException.kt | 4 +- .../errors/UnprocessableEntityException.kt | 4 +- .../com/braintrustdata/api/models/AISecret.kt | 133 +- .../com/braintrustdata/api/models/Acl.kt | 132 +- .../api/models/AclBatchUpdateParams.kt | 823 ++-- .../api/models/AclBatchUpdateResponse.kt | 59 +- .../api/models/AclCreateParams.kt | 1028 ++--- .../api/models/AclDeleteParams.kt | 47 +- .../api/models/AclFindAndDeleteParams.kt | 1038 ++--- .../braintrustdata/api/models/AclListPage.kt | 29 +- .../api/models/AclListPageAsync.kt | 29 +- .../api/models/AclListParams.kt | 52 +- .../api/models/AclRetrieveParams.kt | 22 +- .../api/models/AiSecretCreateParams.kt | 598 +-- .../api/models/AiSecretDeleteParams.kt | 47 +- .../api/models/AiSecretFindAndDeleteParams.kt | 372 +- .../api/models/AiSecretListPage.kt | 29 +- .../api/models/AiSecretListPageAsync.kt | 29 +- .../api/models/AiSecretListParams.kt | 74 +- .../api/models/AiSecretReplaceParams.kt | 598 +-- .../api/models/AiSecretRetrieveParams.kt | 22 +- .../api/models/AiSecretUpdateParams.kt | 495 +-- .../com/braintrustdata/api/models/ApiKey.kt | 82 +- .../api/models/ApiKeyCreateParams.kt | 372 +- .../api/models/ApiKeyDeleteParams.kt | 47 +- .../api/models/ApiKeyListPage.kt | 29 +- .../api/models/ApiKeyListPageAsync.kt | 29 +- .../api/models/ApiKeyListParams.kt | 52 +- .../api/models/ApiKeyRetrieveParams.kt | 22 +- .../models/ChatCompletionContentPartImage.kt | 105 +- .../models/ChatCompletionContentPartText.kt | 52 +- .../models/ChatCompletionMessageToolCall.kt | 114 +- .../braintrustdata/api/models/CodeBundle.kt | 347 +- .../api/models/CreateApiKeyOutput.kt | 87 +- .../api/models/CrossObjectInsertResponse.kt | 178 +- .../braintrustdata/api/models/DataSummary.kt | 51 +- .../com/braintrustdata/api/models/Dataset.kt | 137 +- .../api/models/DatasetCreateParams.kt | 549 +-- .../api/models/DatasetDeleteParams.kt | 47 +- .../braintrustdata/api/models/DatasetEvent.kt | 189 +- .../api/models/DatasetFeedbackParams.kt | 340 +- .../api/models/DatasetFetchParams.kt | 40 +- .../api/models/DatasetFetchPostParams.kt | 945 ++--- .../api/models/DatasetInsertParams.kt | 338 +- .../api/models/DatasetListPage.kt | 29 +- .../api/models/DatasetListPageAsync.kt | 29 +- .../api/models/DatasetListParams.kt | 56 +- .../api/models/DatasetRetrieveParams.kt | 22 +- .../api/models/DatasetSummarizeParams.kt | 34 +- .../api/models/DatasetUpdateParams.kt | 456 +-- .../com/braintrustdata/api/models/EnvVar.kt | 84 +- .../api/models/EnvVarCreateParams.kt | 512 +-- .../api/models/EnvVarDeleteParams.kt | 47 +- .../api/models/EnvVarListParams.kt | 50 +- .../api/models/EnvVarListResponse.kt | 48 +- .../api/models/EnvVarReplaceParams.kt | 512 +-- .../api/models/EnvVarRetrieveParams.kt | 22 +- .../api/models/EnvVarUpdateParams.kt | 372 +- .../api/models/EvalCreateParams.kt | 3574 +++++++++-------- .../braintrustdata/api/models/Experiment.kt | 199 +- .../api/models/ExperimentCreateParams.kt | 1355 ++++--- .../api/models/ExperimentDeleteParams.kt | 47 +- .../api/models/ExperimentEvent.kt | 453 ++- .../api/models/ExperimentFeedbackParams.kt | 340 +- .../api/models/ExperimentFetchParams.kt | 40 +- .../api/models/ExperimentFetchPostParams.kt | 945 ++--- .../api/models/ExperimentInsertParams.kt | 338 +- .../api/models/ExperimentListPage.kt | 30 +- .../api/models/ExperimentListPageAsync.kt | 30 +- .../api/models/ExperimentListParams.kt | 56 +- .../api/models/ExperimentRetrieveParams.kt | 22 +- .../api/models/ExperimentSummarizeParams.kt | 36 +- .../api/models/ExperimentUpdateParams.kt | 1155 +++--- .../api/models/FeedbackDatasetItem.kt | 111 +- .../api/models/FeedbackExperimentItem.kt | 158 +- .../api/models/FeedbackProjectLogsItem.kt | 158 +- .../api/models/FeedbackResponseSchema.kt | 49 +- .../api/models/FetchDatasetEventsResponse.kt | 57 +- .../models/FetchExperimentEventsResponse.kt | 57 +- .../models/FetchProjectLogsEventsResponse.kt | 57 +- .../com/braintrustdata/api/models/Function.kt | 700 ++-- .../api/models/FunctionCreateParams.kt | 1835 +++++---- .../api/models/FunctionDeleteParams.kt | 47 +- .../api/models/FunctionInvokeParams.kt | 1597 ++++---- .../api/models/FunctionInvokeResponse.kt | 42 +- .../api/models/FunctionListPage.kt | 29 +- .../api/models/FunctionListPageAsync.kt | 29 +- .../api/models/FunctionListParams.kt | 60 +- .../api/models/FunctionReplaceParams.kt | 1835 +++++---- .../api/models/FunctionRetrieveParams.kt | 22 +- .../api/models/FunctionUpdateParams.kt | 1211 +++--- .../com/braintrustdata/api/models/Group.kt | 119 +- .../api/models/GroupCreateParams.kt | 832 ++-- .../api/models/GroupDeleteParams.kt | 47 +- .../api/models/GroupListPage.kt | 29 +- .../api/models/GroupListPageAsync.kt | 29 +- .../api/models/GroupListParams.kt | 52 +- .../api/models/GroupReplaceParams.kt | 832 ++-- .../api/models/GroupRetrieveParams.kt | 22 +- .../api/models/GroupUpdateParams.kt | 901 +++-- .../api/models/InsertDatasetEvent.kt | 203 +- .../api/models/InsertEventsResponse.kt | 48 +- .../api/models/InsertExperimentEvent.kt | 455 ++- .../api/models/InsertProjectLogsEvent.kt | 455 ++- .../api/models/MetricSummary.kt | 82 +- .../api/models/ObjectReference.kt | 77 +- .../api/models/OnlineScoreConfig.kt | 183 +- .../braintrustdata/api/models/Organization.kt | 93 +- .../api/models/OrganizationDeleteParams.kt | 47 +- .../api/models/OrganizationListPage.kt | 30 +- .../api/models/OrganizationListPageAsync.kt | 30 +- .../api/models/OrganizationListParams.kt | 50 +- .../models/OrganizationMemberUpdateParams.kt | 857 ++-- .../api/models/OrganizationRetrieveParams.kt | 22 +- .../api/models/OrganizationUpdateParams.kt | 795 ++-- .../models/PatchOrganizationMembersOutput.kt | 63 +- .../com/braintrustdata/api/models/Project.kt | 91 +- .../api/models/ProjectCreateParams.kt | 372 +- .../api/models/ProjectDeleteParams.kt | 47 +- .../api/models/ProjectListPage.kt | 29 +- .../api/models/ProjectListPageAsync.kt | 29 +- .../api/models/ProjectListParams.kt | 52 +- .../api/models/ProjectLogFeedbackParams.kt | 340 +- .../api/models/ProjectLogFetchParams.kt | 40 +- .../api/models/ProjectLogFetchPostParams.kt | 945 ++--- .../api/models/ProjectLogInsertParams.kt | 338 +- .../api/models/ProjectLogsEvent.kt | 455 ++- .../api/models/ProjectRetrieveParams.kt | 22 +- .../braintrustdata/api/models/ProjectScore.kt | 167 +- .../api/models/ProjectScoreCategory.kt | 52 +- .../api/models/ProjectScoreConfig.kt | 74 +- .../api/models/ProjectScoreCreateParams.kt | 975 ++--- .../api/models/ProjectScoreDeleteParams.kt | 47 +- .../api/models/ProjectScoreListPage.kt | 30 +- .../api/models/ProjectScoreListPageAsync.kt | 30 +- .../api/models/ProjectScoreListParams.kt | 82 +- .../api/models/ProjectScoreReplaceParams.kt | 975 ++--- .../api/models/ProjectScoreRetrieveParams.kt | 22 +- .../api/models/ProjectScoreUpdateParams.kt | 908 ++--- .../api/models/ProjectSettings.kt | 141 +- .../braintrustdata/api/models/ProjectTag.kt | 89 +- .../api/models/ProjectTagCreateParams.kt | 516 +-- .../api/models/ProjectTagDeleteParams.kt | 47 +- .../api/models/ProjectTagListPage.kt | 30 +- .../api/models/ProjectTagListPageAsync.kt | 30 +- .../api/models/ProjectTagListParams.kt | 56 +- .../api/models/ProjectTagReplaceParams.kt | 516 +-- .../api/models/ProjectTagRetrieveParams.kt | 22 +- .../api/models/ProjectTagUpdateParams.kt | 431 +- .../api/models/ProjectUpdateParams.kt | 364 +- .../com/braintrustdata/api/models/Prompt.kt | 182 +- .../api/models/PromptCreateParams.kt | 1002 ++--- .../braintrustdata/api/models/PromptData.kt | 930 +++-- .../api/models/PromptDeleteParams.kt | 47 +- .../api/models/PromptListPage.kt | 29 +- .../api/models/PromptListPageAsync.kt | 29 +- .../api/models/PromptListParams.kt | 60 +- .../api/models/PromptOptions.kt | 947 +++-- .../api/models/PromptReplaceParams.kt | 1002 ++--- .../api/models/PromptRetrieveParams.kt | 22 +- .../api/models/PromptUpdateParams.kt | 802 ++-- .../com/braintrustdata/api/models/RepoInfo.kt | 120 +- .../com/braintrustdata/api/models/Role.kt | 176 +- .../api/models/RoleCreateParams.kt | 977 ++--- .../api/models/RoleDeleteParams.kt | 47 +- .../braintrustdata/api/models/RoleListPage.kt | 29 +- .../api/models/RoleListPageAsync.kt | 29 +- .../api/models/RoleListParams.kt | 52 +- .../api/models/RoleReplaceParams.kt | 981 ++--- .../api/models/RoleRetrieveParams.kt | 22 +- .../api/models/RoleUpdateParams.kt | 1268 +++--- .../braintrustdata/api/models/ScoreSummary.kt | 75 +- .../api/models/SpanAttributes.kt | 53 +- .../braintrustdata/api/models/SpanIFrame.kt | 118 +- .../api/models/SpanIframeCreateParams.kt | 571 +-- .../api/models/SpanIframeDeleteParams.kt | 47 +- .../api/models/SpanIframeListPage.kt | 30 +- .../api/models/SpanIframeListPageAsync.kt | 30 +- .../api/models/SpanIframeListParams.kt | 52 +- .../api/models/SpanIframeReplaceParams.kt | 571 +-- .../api/models/SpanIframeRetrieveParams.kt | 22 +- .../api/models/SpanIframeUpdateParams.kt | 536 +-- .../api/models/SummarizeDatasetResponse.kt | 87 +- .../api/models/SummarizeExperimentResponse.kt | 184 +- .../api/models/TopLevelHelloWorldParams.kt | 10 +- .../com/braintrustdata/api/models/User.kt | 84 +- .../braintrustdata/api/models/UserListPage.kt | 29 +- .../api/models/UserListPageAsync.kt | 29 +- .../api/models/UserListParams.kt | 116 +- .../api/models/UserRetrieveParams.kt | 22 +- .../com/braintrustdata/api/models/View.kt | 126 +- .../api/models/ViewCreateParams.kt | 1052 ++--- .../com/braintrustdata/api/models/ViewData.kt | 49 +- .../api/models/ViewDataSearch.kt | 73 +- .../api/models/ViewDeleteParams.kt | 390 +- .../braintrustdata/api/models/ViewListPage.kt | 29 +- .../api/models/ViewListPageAsync.kt | 29 +- .../api/models/ViewListParams.kt | 56 +- .../braintrustdata/api/models/ViewOptions.kt | 171 +- .../api/models/ViewReplaceParams.kt | 1060 ++--- .../api/models/ViewRetrieveParams.kt | 36 +- .../api/models/ViewUpdateParams.kt | 981 ++--- .../api/core/http/SerializerTest.kt | 2 - 215 files changed, 30862 insertions(+), 28280 deletions(-) diff --git a/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClient.kt b/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClient.kt index 3800c0ed..f94c4c36 100755 --- a/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClient.kt +++ b/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClient.kt @@ -38,6 +38,17 @@ class BraintrustOkHttpClient private constructor() { this.baseUrl = baseUrl } + /** + * Whether to throw an exception if any of the Jackson versions detected at runtime are + * incompatible with the SDK's minimum supported Jackson version (2.13.4). + * + * Defaults to true. Use extreme caution when disabling this option. There is no guarantee + * that the SDK will work correctly when using an incompatible Jackson version. + */ + fun checkJacksonVersionCompatibility(checkJacksonVersionCompatibility: Boolean) = apply { + clientOptions.checkJacksonVersionCompatibility(checkJacksonVersionCompatibility) + } + fun jsonMapper(jsonMapper: JsonMapper) = apply { clientOptions.jsonMapper(jsonMapper) } fun clock(clock: Clock) = apply { clientOptions.clock(clock) } diff --git a/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClientAsync.kt b/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClientAsync.kt index 52efdd0a..861216ed 100755 --- a/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClientAsync.kt +++ b/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClientAsync.kt @@ -40,6 +40,17 @@ class BraintrustOkHttpClientAsync private constructor() { this.baseUrl = baseUrl } + /** + * Whether to throw an exception if any of the Jackson versions detected at runtime are + * incompatible with the SDK's minimum supported Jackson version (2.13.4). + * + * Defaults to true. Use extreme caution when disabling this option. There is no guarantee + * that the SDK will work correctly when using an incompatible Jackson version. + */ + fun checkJacksonVersionCompatibility(checkJacksonVersionCompatibility: Boolean) = apply { + clientOptions.checkJacksonVersionCompatibility(checkJacksonVersionCompatibility) + } + fun jsonMapper(jsonMapper: JsonMapper) = apply { clientOptions.jsonMapper(jsonMapper) } fun clock(clock: Clock) = apply { clientOptions.clock(clock) } diff --git a/braintrust-java-core/build.gradle.kts b/braintrust-java-core/build.gradle.kts index 4d9c5428..1fd4b0fd 100755 --- a/braintrust-java-core/build.gradle.kts +++ b/braintrust-java-core/build.gradle.kts @@ -3,6 +3,19 @@ plugins { id("braintrust.publish") } +configurations.all { + resolutionStrategy { + // Compile and test against a lower Jackson version to ensure we're compatible with it. + // We publish with a higher version (see below) to ensure users depend on a secure version by default. + force("com.fasterxml.jackson.core:jackson-core:2.13.4") + force("com.fasterxml.jackson.core:jackson-databind:2.13.4") + force("com.fasterxml.jackson.core:jackson-annotations:2.13.4") + force("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.13.4") + force("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.4") + force("com.fasterxml.jackson.module:jackson-module-kotlin:2.13.4") + } +} + dependencies { api("com.fasterxml.jackson.core:jackson-core:2.18.1") api("com.fasterxml.jackson.core:jackson-databind:2.18.1") diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Check.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Check.kt index 4a2305ea..40e95a5a 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Check.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Check.kt @@ -2,6 +2,9 @@ package com.braintrustdata.api.core +import com.fasterxml.jackson.core.Version +import com.fasterxml.jackson.core.util.VersionUtil + fun checkRequired(name: String, value: T?): T = checkNotNull(value) { "`$name` is required, but was not set" } @@ -39,3 +42,46 @@ internal fun checkMaxLength(name: String, value: String, maxLength: Int): String "`$name` must have at most length $maxLength, but was ${it.length}" } } + +@JvmSynthetic +internal fun checkJacksonVersionCompatibility() { + val incompatibleJacksonVersions = + RUNTIME_JACKSON_VERSIONS.mapNotNull { + when { + it.majorVersion != MINIMUM_JACKSON_VERSION.majorVersion -> + it to "incompatible major version" + it.minorVersion < MINIMUM_JACKSON_VERSION.minorVersion -> + it to "minor version too low" + it.minorVersion == MINIMUM_JACKSON_VERSION.minorVersion && + it.patchLevel < MINIMUM_JACKSON_VERSION.patchLevel -> + it to "patch version too low" + else -> null + } + } + check(incompatibleJacksonVersions.isEmpty()) { + """ +This SDK depends on Jackson version $MINIMUM_JACKSON_VERSION, but the following incompatible Jackson versions were detected at runtime: + +${incompatibleJacksonVersions.asSequence().map { (version, incompatibilityReason) -> + "- `${version.toFullString().replace("/", ":")}` ($incompatibilityReason)" +}.joinToString("\n")} + +This can happen if you are either: +1. Directly depending on different Jackson versions +2. Depending on some library that depends on different Jackson versions, potentially transitively + +Double-check that you are depending on compatible Jackson versions. + """ + .trimIndent() + } +} + +private val MINIMUM_JACKSON_VERSION: Version = VersionUtil.parseVersion("2.13.4", null, null) +private val RUNTIME_JACKSON_VERSIONS: List = + listOf( + com.fasterxml.jackson.core.json.PackageVersion.VERSION, + com.fasterxml.jackson.databind.cfg.PackageVersion.VERSION, + com.fasterxml.jackson.datatype.jdk8.PackageVersion.VERSION, + com.fasterxml.jackson.datatype.jsr310.PackageVersion.VERSION, + com.fasterxml.jackson.module.kotlin.PackageVersion.VERSION, + ) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ClientOptions.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ClientOptions.kt index 53b6d493..269345b4 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ClientOptions.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ClientOptions.kt @@ -16,6 +16,7 @@ class ClientOptions private constructor( private val originalHttpClient: HttpClient, @get:JvmName("httpClient") val httpClient: HttpClient, + @get:JvmName("checkJacksonVersionCompatibility") val checkJacksonVersionCompatibility: Boolean, @get:JvmName("jsonMapper") val jsonMapper: JsonMapper, @get:JvmName("clock") val clock: Clock, @get:JvmName("baseUrl") val baseUrl: String, @@ -27,6 +28,12 @@ private constructor( private val apiKey: String?, ) { + init { + if (checkJacksonVersionCompatibility) { + checkJacksonVersionCompatibility() + } + } + fun apiKey(): Optional = Optional.ofNullable(apiKey) fun toBuilder() = Builder().from(this) @@ -52,6 +59,7 @@ private constructor( class Builder internal constructor() { private var httpClient: HttpClient? = null + private var checkJacksonVersionCompatibility: Boolean = true private var jsonMapper: JsonMapper = jsonMapper() private var clock: Clock = Clock.systemUTC() private var baseUrl: String = PRODUCTION_URL @@ -65,6 +73,7 @@ private constructor( @JvmSynthetic internal fun from(clientOptions: ClientOptions) = apply { httpClient = clientOptions.originalHttpClient + checkJacksonVersionCompatibility = clientOptions.checkJacksonVersionCompatibility jsonMapper = clientOptions.jsonMapper clock = clientOptions.clock baseUrl = clientOptions.baseUrl @@ -78,6 +87,10 @@ private constructor( fun httpClient(httpClient: HttpClient) = apply { this.httpClient = httpClient } + fun checkJacksonVersionCompatibility(checkJacksonVersionCompatibility: Boolean) = apply { + this.checkJacksonVersionCompatibility = checkJacksonVersionCompatibility + } + fun jsonMapper(jsonMapper: JsonMapper) = apply { this.jsonMapper = jsonMapper } fun clock(clock: Clock) = apply { this.clock = clock } @@ -220,6 +233,7 @@ private constructor( .maxRetries(maxRetries) .build() ), + checkJacksonVersionCompatibility, jsonMapper, clock, baseUrl, diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ObjectMappers.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ObjectMappers.kt index 588027c6..f6ed60e5 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ObjectMappers.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ObjectMappers.kt @@ -2,26 +2,22 @@ package com.braintrustdata.api.core -import com.braintrustdata.api.errors.BraintrustException -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.core.JsonGenerator import com.fasterxml.jackson.databind.DeserializationFeature +import com.fasterxml.jackson.databind.MapperFeature import com.fasterxml.jackson.databind.SerializationFeature import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.cfg.CoercionAction.Fail -import com.fasterxml.jackson.databind.cfg.CoercionInputShape.Integer -import com.fasterxml.jackson.databind.exc.InvalidDefinitionException -import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException import com.fasterxml.jackson.databind.json.JsonMapper import com.fasterxml.jackson.databind.module.SimpleModule import com.fasterxml.jackson.datatype.jdk8.Jdk8Module import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule -import com.fasterxml.jackson.module.kotlin.jacksonMapperBuilder +import com.fasterxml.jackson.module.kotlin.kotlinModule import java.io.InputStream fun jsonMapper(): JsonMapper = - jacksonMapperBuilder() + JsonMapper.builder() + .addModule(kotlinModule()) .addModule(Jdk8Module()) .addModule(JavaTimeModule()) .addModule(SimpleModule().addSerializer(InputStreamJsonSerializer)) @@ -30,7 +26,12 @@ fun jsonMapper(): JsonMapper = .disable(SerializationFeature.FLUSH_AFTER_WRITE_VALUE) .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) .disable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS) - .withCoercionConfig(String::class.java) { it.setCoercion(Integer, Fail) } + .disable(MapperFeature.ALLOW_COERCION_OF_SCALARS) + .disable(MapperFeature.AUTO_DETECT_CREATORS) + .disable(MapperFeature.AUTO_DETECT_FIELDS) + .disable(MapperFeature.AUTO_DETECT_GETTERS) + .disable(MapperFeature.AUTO_DETECT_IS_GETTERS) + .disable(MapperFeature.AUTO_DETECT_SETTERS) .build() private object InputStreamJsonSerializer : BaseSerializer(InputStream::class) { @@ -47,38 +48,3 @@ private object InputStreamJsonSerializer : BaseSerializer(InputStre } } } - -@JvmSynthetic -internal fun enhanceJacksonException(fallbackMessage: String, e: Exception): Exception { - // These exceptions should only happen if our code is wrong OR if the user is using a binary - // incompatible version of `com.fasterxml.jackson.core:jackson-databind`: - // https://javadoc.io/static/com.fasterxml.jackson.core/jackson-databind/2.18.1/index.html - val isUnexpectedException = - e is UnrecognizedPropertyException || e is InvalidDefinitionException - if (!isUnexpectedException) { - return BraintrustInvalidDataException(fallbackMessage, e) - } - - val jacksonVersion = JsonMapper::class.java.`package`.implementationVersion - if (jacksonVersion.isNullOrEmpty() || jacksonVersion == COMPILED_JACKSON_VERSION) { - return BraintrustInvalidDataException(fallbackMessage, e) - } - - return BraintrustException( - """ - Jackson threw an unexpected exception and its runtime version ($jacksonVersion) mismatches the version the SDK was compiled with ($COMPILED_JACKSON_VERSION). - - You may be using a version of `com.fasterxml.jackson.core:jackson-databind` that's not binary compatible with the SDK. - - This can happen if you are either: - 1. Directly depending on a different Jackson version - 2. Depending on some library that depends on a different Jackson version, potentially transitively - - Double-check that you are depending on a compatible Jackson version. - """ - .trimIndent(), - e, - ) -} - -const val COMPILED_JACKSON_VERSION = "2.18.1" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Values.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Values.kt index c25a05d5..0cb5f8bf 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Values.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Values.kt @@ -2,8 +2,6 @@ package com.braintrustdata.api.core import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JacksonAnnotationsInside -import com.fasterxml.jackson.annotation.JsonAutoDetect -import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.core.JsonGenerator @@ -451,19 +449,9 @@ private constructor( @JsonInclude(JsonInclude.Include.CUSTOM, valueFilter = JsonField.IsMissing::class) annotation class ExcludeMissing -@JacksonAnnotationsInside -@JsonAutoDetect( - getterVisibility = Visibility.NONE, - isGetterVisibility = Visibility.NONE, - setterVisibility = Visibility.NONE, - creatorVisibility = Visibility.NONE, - fieldVisibility = Visibility.NONE, -) -annotation class NoAutoDetect - class MultipartField private constructor( - @get:JvmName("value") val value: JsonField, + @get:com.fasterxml.jackson.annotation.JsonValue @get:JvmName("value") val value: JsonField, @get:JvmName("contentType") val contentType: String, private val filename: String?, ) { @@ -481,11 +469,7 @@ private constructor( @JvmSynthetic internal fun map(transform: (T) -> R): MultipartField = - MultipartField.builder() - .value(value.map(transform)) - .contentType(contentType) - .filename(filename) - .build() + builder().value(value.map(transform)).contentType(contentType).filename(filename).build() /** A builder for [MultipartField]. */ class Builder internal constructor() { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/handlers/JsonHandler.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/handlers/JsonHandler.kt index ae855a7b..70259a46 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/handlers/JsonHandler.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/handlers/JsonHandler.kt @@ -2,9 +2,9 @@ package com.braintrustdata.api.core.handlers -import com.braintrustdata.api.core.enhanceJacksonException import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.databind.json.JsonMapper import com.fasterxml.jackson.module.kotlin.jacksonTypeRef @@ -15,6 +15,6 @@ internal inline fun jsonHandler(jsonMapper: JsonMapper): Handler try { jsonMapper.readValue(response.body(), jacksonTypeRef()) } catch (e: Exception) { - throw enhanceJacksonException("Error reading response", e) + throw BraintrustInvalidDataException("Error reading response", e) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BadRequestException.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BadRequestException.kt index 4f0ec4e2..9e02c395 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BadRequestException.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BadRequestException.kt @@ -12,12 +12,12 @@ class BadRequestException private constructor(private val headers: Headers, private val body: JsonValue, cause: Throwable?) : BraintrustServiceException("400: $body", cause) { + override fun statusCode(): Int = 400 + override fun headers(): Headers = headers override fun body(): JsonValue = body - override fun statusCode(): Int = 400 - fun toBuilder() = Builder().from(this) companion object { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/NotFoundException.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/NotFoundException.kt index 2d0ca370..d31d5688 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/NotFoundException.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/NotFoundException.kt @@ -12,12 +12,12 @@ class NotFoundException private constructor(private val headers: Headers, private val body: JsonValue, cause: Throwable?) : BraintrustServiceException("404: $body", cause) { + override fun statusCode(): Int = 404 + override fun headers(): Headers = headers override fun body(): JsonValue = body - override fun statusCode(): Int = 404 - fun toBuilder() = Builder().from(this) companion object { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/PermissionDeniedException.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/PermissionDeniedException.kt index 7270819a..b6926f3f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/PermissionDeniedException.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/PermissionDeniedException.kt @@ -12,12 +12,12 @@ class PermissionDeniedException private constructor(private val headers: Headers, private val body: JsonValue, cause: Throwable?) : BraintrustServiceException("403: $body", cause) { + override fun statusCode(): Int = 403 + override fun headers(): Headers = headers override fun body(): JsonValue = body - override fun statusCode(): Int = 403 - fun toBuilder() = Builder().from(this) companion object { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/RateLimitException.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/RateLimitException.kt index 79d7d627..cb32fed9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/RateLimitException.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/RateLimitException.kt @@ -12,12 +12,12 @@ class RateLimitException private constructor(private val headers: Headers, private val body: JsonValue, cause: Throwable?) : BraintrustServiceException("429: $body", cause) { + override fun statusCode(): Int = 429 + override fun headers(): Headers = headers override fun body(): JsonValue = body - override fun statusCode(): Int = 429 - fun toBuilder() = Builder().from(this) companion object { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/UnauthorizedException.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/UnauthorizedException.kt index e7cf6f20..55d60f4c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/UnauthorizedException.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/UnauthorizedException.kt @@ -12,12 +12,12 @@ class UnauthorizedException private constructor(private val headers: Headers, private val body: JsonValue, cause: Throwable?) : BraintrustServiceException("401: $body", cause) { + override fun statusCode(): Int = 401 + override fun headers(): Headers = headers override fun body(): JsonValue = body - override fun statusCode(): Int = 401 - fun toBuilder() = Builder().from(this) companion object { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/UnprocessableEntityException.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/UnprocessableEntityException.kt index a4d91061..22101f46 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/UnprocessableEntityException.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/UnprocessableEntityException.kt @@ -12,12 +12,12 @@ class UnprocessableEntityException private constructor(private val headers: Headers, private val body: JsonValue, cause: Throwable?) : BraintrustServiceException("422: $body", cause) { + override fun statusCode(): Int = 422 + override fun headers(): Headers = headers override fun body(): JsonValue = body - override fun statusCode(): Int = 422 - fun toBuilder() = Builder().from(this) companion object { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AISecret.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AISecret.kt index 1019fd7b..364b5190 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AISecret.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AISecret.kt @@ -6,43 +6,49 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class AISecret -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing private val name: JsonField = JsonMissing.of(), - @JsonProperty("org_id") @ExcludeMissing private val orgId: JsonField = JsonMissing.of(), - @JsonProperty("created") - @ExcludeMissing - private val created: JsonField = JsonMissing.of(), - @JsonProperty("metadata") - @ExcludeMissing - private val metadata: JsonField = JsonMissing.of(), - @JsonProperty("preview_secret") - @ExcludeMissing - private val previewSecret: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing private val type: JsonField = JsonMissing.of(), - @JsonProperty("updated_at") - @ExcludeMissing - private val updatedAt: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val name: JsonField, + private val orgId: JsonField, + private val created: JsonField, + private val metadata: JsonField, + private val previewSecret: JsonField, + private val type: JsonField, + private val updatedAt: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("org_id") @ExcludeMissing orgId: JsonField = JsonMissing.of(), + @JsonProperty("created") + @ExcludeMissing + created: JsonField = JsonMissing.of(), + @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("preview_secret") + @ExcludeMissing + previewSecret: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("updated_at") + @ExcludeMissing + updatedAt: JsonField = JsonMissing.of(), + ) : this(id, name, orgId, created, metadata, previewSecret, type, updatedAt, mutableMapOf()) + /** * Unique identifier for the AI secret * @@ -163,27 +169,15 @@ private constructor( @ExcludeMissing fun _updatedAt(): JsonField = updatedAt + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): AISecret = apply { - if (validated) { - return@apply - } - - id() - name() - orgId() - created() - metadata().ifPresent { it.validate() } - previewSecret() - type() - updatedAt() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -379,32 +373,43 @@ private constructor( previewSecret, type, updatedAt, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } - @NoAutoDetect - class Metadata - @JsonCreator - private constructor( - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private var validated: Boolean = false - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun validate(): AISecret = apply { + if (validated) { + return@apply + } - private var validated: Boolean = false + id() + name() + orgId() + created() + metadata().ifPresent { it.validate() } + previewSecret() + type() + updatedAt() + validated = true + } - fun validate(): Metadata = apply { - if (validated) { - return@apply - } + class Metadata + private constructor(private val additionalProperties: MutableMap) { - validated = true + @JsonCreator private constructor() : this(mutableMapOf()) + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + fun toBuilder() = Builder().from(this) companion object { @@ -447,7 +452,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Acl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Acl.kt index 514087dd..57225fc1 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Acl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Acl.kt @@ -6,16 +6,14 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -30,41 +28,57 @@ import kotlin.jvm.optionals.getOrNull * To restrict a grant to a particular sub-object, you may specify `restrict_object_type` in the * ACL, as part of a direct permission grant or as part of a role. */ -@NoAutoDetect class Acl -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("_object_org_id") - @ExcludeMissing - private val _objectOrgId: JsonField = JsonMissing.of(), - @JsonProperty("object_id") - @ExcludeMissing - private val objectId: JsonField = JsonMissing.of(), - @JsonProperty("object_type") - @ExcludeMissing - private val objectType: JsonField = JsonMissing.of(), - @JsonProperty("created") - @ExcludeMissing - private val created: JsonField = JsonMissing.of(), - @JsonProperty("group_id") - @ExcludeMissing - private val groupId: JsonField = JsonMissing.of(), - @JsonProperty("permission") - @ExcludeMissing - private val permission: JsonField = JsonMissing.of(), - @JsonProperty("restrict_object_type") - @ExcludeMissing - private val restrictObjectType: JsonField = JsonMissing.of(), - @JsonProperty("role_id") - @ExcludeMissing - private val roleId: JsonField = JsonMissing.of(), - @JsonProperty("user_id") - @ExcludeMissing - private val userId: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val _objectOrgId: JsonField, + private val objectId: JsonField, + private val objectType: JsonField, + private val created: JsonField, + private val groupId: JsonField, + private val permission: JsonField, + private val restrictObjectType: JsonField, + private val roleId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("_object_org_id") + @ExcludeMissing + _objectOrgId: JsonField = JsonMissing.of(), + @JsonProperty("object_id") @ExcludeMissing objectId: JsonField = JsonMissing.of(), + @JsonProperty("object_type") + @ExcludeMissing + objectType: JsonField = JsonMissing.of(), + @JsonProperty("created") + @ExcludeMissing + created: JsonField = JsonMissing.of(), + @JsonProperty("group_id") @ExcludeMissing groupId: JsonField = JsonMissing.of(), + @JsonProperty("permission") + @ExcludeMissing + permission: JsonField = JsonMissing.of(), + @JsonProperty("restrict_object_type") + @ExcludeMissing + restrictObjectType: JsonField = JsonMissing.of(), + @JsonProperty("role_id") @ExcludeMissing roleId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), + ) : this( + id, + _objectOrgId, + objectId, + objectType, + created, + groupId, + permission, + restrictObjectType, + roleId, + userId, + mutableMapOf(), + ) + /** * Unique identifier for the acl * @@ -227,29 +241,15 @@ private constructor( */ @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Acl = apply { - if (validated) { - return@apply - } - - id() - _objectOrgId() - objectId() - objectType() - created() - groupId() - permission() - restrictObjectType() - roleId() - userId() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -499,10 +499,30 @@ private constructor( restrictObjectType, roleId, userId, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Acl = apply { + if (validated) { + return@apply + } + + id() + _objectOrgId() + objectId() + objectType() + created() + groupId() + permission() + restrictObjectType() + roleId() + userId() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateParams.kt index de92b67f..8b930279 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateParams.kt @@ -6,19 +6,18 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -84,241 +83,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("add_acls") - @ExcludeMissing - private val addAcls: JsonField> = JsonMissing.of(), - @JsonProperty("remove_acls") - @ExcludeMissing - private val removeAcls: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { - - /** - * An ACL grants a certain permission or role to a certain user or group on an object. - * - * ACLs are inherited across the object hierarchy. So for example, if a user has read - * permissions on a project, they will also have read permissions on any experiment, - * dataset, etc. created within that project. - * - * To restrict a grant to a particular sub-object, you may specify `restrict_object_type` in - * the ACL, as part of a direct permission grant or as part of a role. - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun addAcls(): Optional> = Optional.ofNullable(addAcls.getNullable("add_acls")) - - /** - * An ACL grants a certain permission or role to a certain user or group on an object. - * - * ACLs are inherited across the object hierarchy. So for example, if a user has read - * permissions on a project, they will also have read permissions on any experiment, - * dataset, etc. created within that project. - * - * To restrict a grant to a particular sub-object, you may specify `restrict_object_type` in - * the ACL, as part of a direct permission grant or as part of a role. - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun removeAcls(): Optional> = - Optional.ofNullable(removeAcls.getNullable("remove_acls")) - - /** - * Returns the raw JSON value of [addAcls]. - * - * Unlike [addAcls], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("add_acls") @ExcludeMissing fun _addAcls(): JsonField> = addAcls - - /** - * Returns the raw JSON value of [removeAcls]. - * - * Unlike [removeAcls], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("remove_acls") - @ExcludeMissing - fun _removeAcls(): JsonField> = removeAcls - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } - - addAcls().ifPresent { it.forEach { it.validate() } } - removeAcls().ifPresent { it.forEach { it.validate() } } - validated = true - } - - fun toBuilder() = Builder().from(this) - - companion object { - - /** Returns a mutable builder for constructing an instance of [Body]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var addAcls: JsonField>? = null - private var removeAcls: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - addAcls = body.addAcls.map { it.toMutableList() } - removeAcls = body.removeAcls.map { it.toMutableList() } - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** - * An ACL grants a certain permission or role to a certain user or group on an object. - * - * ACLs are inherited across the object hierarchy. So for example, if a user has read - * permissions on a project, they will also have read permissions on any experiment, - * dataset, etc. created within that project. - * - * To restrict a grant to a particular sub-object, you may specify - * `restrict_object_type` in the ACL, as part of a direct permission grant or as part of - * a role. - */ - fun addAcls(addAcls: List?) = addAcls(JsonField.ofNullable(addAcls)) - - /** Alias for calling [Builder.addAcls] with `addAcls.orElse(null)`. */ - fun addAcls(addAcls: Optional>) = addAcls(addAcls.getOrNull()) - - /** - * Sets [Builder.addAcls] to an arbitrary JSON value. - * - * You should usually call [Builder.addAcls] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun addAcls(addAcls: JsonField>) = apply { - this.addAcls = addAcls.map { it.toMutableList() } - } - - /** - * Adds a single [AddAcl] to [addAcls]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addAddAcl(addAcl: AddAcl) = apply { - addAcls = - (addAcls ?: JsonField.of(mutableListOf())).also { - checkKnown("addAcls", it).add(addAcl) - } - } - - /** - * An ACL grants a certain permission or role to a certain user or group on an object. - * - * ACLs are inherited across the object hierarchy. So for example, if a user has read - * permissions on a project, they will also have read permissions on any experiment, - * dataset, etc. created within that project. - * - * To restrict a grant to a particular sub-object, you may specify - * `restrict_object_type` in the ACL, as part of a direct permission grant or as part of - * a role. - */ - fun removeAcls(removeAcls: List?) = - removeAcls(JsonField.ofNullable(removeAcls)) - - /** Alias for calling [Builder.removeAcls] with `removeAcls.orElse(null)`. */ - fun removeAcls(removeAcls: Optional>) = - removeAcls(removeAcls.getOrNull()) - - /** - * Sets [Builder.removeAcls] to an arbitrary JSON value. - * - * You should usually call [Builder.removeAcls] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun removeAcls(removeAcls: JsonField>) = apply { - this.removeAcls = removeAcls.map { it.toMutableList() } - } - - /** - * Adds a single [RemoveAcl] to [removeAcls]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addRemoveAcl(removeAcl: RemoveAcl) = apply { - removeAcls = - (removeAcls ?: JsonField.of(mutableListOf())).also { - checkKnown("removeAcls", it).add(removeAcl) - } - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - 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) - } - - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Body = - Body( - (addAcls ?: JsonMissing.of()).map { it.toImmutable() }, - (removeAcls ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), - ) - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Body && addAcls == other.addAcls && removeAcls == other.removeAcls && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(addAcls, removeAcls, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Body{addAcls=$addAcls, removeAcls=$removeAcls, additionalProperties=$additionalProperties}" - } - fun toBuilder() = Builder().from(this) companion object { @@ -330,7 +94,6 @@ private constructor( } /** A builder for [AclBatchUpdateParams]. */ - @NoAutoDetect class Builder internal constructor() { private var body: Body.Builder = Body.builder() @@ -449,93 +212,337 @@ private constructor( this.additionalHeaders.putAll(additionalHeaders) } - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(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 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) + } + + /** + * Returns an immutable instance of [AclBatchUpdateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): AclBatchUpdateParams = + AclBatchUpdateParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + @JvmSynthetic internal fun _body(): Body = body + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val addAcls: JsonField>, + private val removeAcls: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("add_acls") + @ExcludeMissing + addAcls: JsonField> = JsonMissing.of(), + @JsonProperty("remove_acls") + @ExcludeMissing + removeAcls: JsonField> = JsonMissing.of(), + ) : this(addAcls, removeAcls, mutableMapOf()) + + /** + * An ACL grants a certain permission or role to a certain user or group on an object. + * + * ACLs are inherited across the object hierarchy. So for example, if a user has read + * permissions on a project, they will also have read permissions on any experiment, + * dataset, etc. created within that project. + * + * To restrict a grant to a particular sub-object, you may specify `restrict_object_type` in + * the ACL, as part of a direct permission grant or as part of a role. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun addAcls(): Optional> = Optional.ofNullable(addAcls.getNullable("add_acls")) + + /** + * An ACL grants a certain permission or role to a certain user or group on an object. + * + * ACLs are inherited across the object hierarchy. So for example, if a user has read + * permissions on a project, they will also have read permissions on any experiment, + * dataset, etc. created within that project. + * + * To restrict a grant to a particular sub-object, you may specify `restrict_object_type` in + * the ACL, as part of a direct permission grant or as part of a role. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun removeAcls(): Optional> = + Optional.ofNullable(removeAcls.getNullable("remove_acls")) + + /** + * Returns the raw JSON value of [addAcls]. + * + * Unlike [addAcls], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("add_acls") @ExcludeMissing fun _addAcls(): JsonField> = addAcls + + /** + * Returns the raw JSON value of [removeAcls]. + * + * Unlike [removeAcls], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("remove_acls") + @ExcludeMissing + fun _removeAcls(): JsonField> = removeAcls + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Body]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var addAcls: JsonField>? = null + private var removeAcls: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + addAcls = body.addAcls.map { it.toMutableList() } + removeAcls = body.removeAcls.map { it.toMutableList() } + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** + * An ACL grants a certain permission or role to a certain user or group on an object. + * + * ACLs are inherited across the object hierarchy. So for example, if a user has read + * permissions on a project, they will also have read permissions on any experiment, + * dataset, etc. created within that project. + * + * To restrict a grant to a particular sub-object, you may specify + * `restrict_object_type` in the ACL, as part of a direct permission grant or as part of + * a role. + */ + fun addAcls(addAcls: List?) = addAcls(JsonField.ofNullable(addAcls)) + + /** Alias for calling [Builder.addAcls] with `addAcls.orElse(null)`. */ + fun addAcls(addAcls: Optional>) = addAcls(addAcls.getOrNull()) + + /** + * Sets [Builder.addAcls] to an arbitrary JSON value. + * + * You should usually call [Builder.addAcls] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun addAcls(addAcls: JsonField>) = apply { + this.addAcls = addAcls.map { it.toMutableList() } + } + + /** + * Adds a single [AddAcl] to [addAcls]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAddAcl(addAcl: AddAcl) = apply { + addAcls = + (addAcls ?: JsonField.of(mutableListOf())).also { + checkKnown("addAcls", it).add(addAcl) + } + } - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } + /** + * An ACL grants a certain permission or role to a certain user or group on an object. + * + * ACLs are inherited across the object hierarchy. So for example, if a user has read + * permissions on a project, they will also have read permissions on any experiment, + * dataset, etc. created within that project. + * + * To restrict a grant to a particular sub-object, you may specify + * `restrict_object_type` in the ACL, as part of a direct permission grant or as part of + * a role. + */ + fun removeAcls(removeAcls: List?) = + removeAcls(JsonField.ofNullable(removeAcls)) - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } + /** Alias for calling [Builder.removeAcls] with `removeAcls.orElse(null)`. */ + fun removeAcls(removeAcls: Optional>) = + removeAcls(removeAcls.getOrNull()) - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** + * Sets [Builder.removeAcls] to an arbitrary JSON value. + * + * You should usually call [Builder.removeAcls] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun removeAcls(removeAcls: JsonField>) = apply { + this.removeAcls = removeAcls.map { it.toMutableList() } + } - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** + * Adds a single [RemoveAcl] to [removeAcls]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRemoveAcl(removeAcl: RemoveAcl) = apply { + removeAcls = + (removeAcls ?: JsonField.of(mutableListOf())).also { + checkKnown("removeAcls", it).add(removeAcl) + } + } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Body = + Body( + (addAcls ?: JsonMissing.of()).map { it.toImmutable() }, + (removeAcls ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } + private var validated: Boolean = false - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + fun validate(): Body = apply { + if (validated) { + return@apply } - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) + addAcls().ifPresent { it.forEach { it.validate() } } + removeAcls().ifPresent { it.forEach { it.validate() } } + validated = true } - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + return /* spotless:off */ other is Body && addAcls == other.addAcls && removeAcls == other.removeAcls && additionalProperties == other.additionalProperties /* spotless:on */ } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) - } - - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(addAcls, removeAcls, additionalProperties) } + /* spotless:on */ - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) - } + override fun hashCode(): Int = hashCode - /** - * Returns an immutable instance of [AclBatchUpdateParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): AclBatchUpdateParams = - AclBatchUpdateParams( - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + override fun toString() = + "Body{addAcls=$addAcls, removeAcls=$removeAcls, additionalProperties=$additionalProperties}" } /** @@ -548,35 +555,46 @@ private constructor( * To restrict a grant to a particular sub-object, you may specify `restrict_object_type` in the * ACL, as part of a direct permission grant or as part of a role. */ - @NoAutoDetect class AddAcl - @JsonCreator private constructor( - @JsonProperty("object_id") - @ExcludeMissing - private val objectId: JsonField = JsonMissing.of(), - @JsonProperty("object_type") - @ExcludeMissing - private val objectType: JsonField = JsonMissing.of(), - @JsonProperty("group_id") - @ExcludeMissing - private val groupId: JsonField = JsonMissing.of(), - @JsonProperty("permission") - @ExcludeMissing - private val permission: JsonField = JsonMissing.of(), - @JsonProperty("restrict_object_type") - @ExcludeMissing - private val restrictObjectType: JsonField = JsonMissing.of(), - @JsonProperty("role_id") - @ExcludeMissing - private val roleId: JsonField = JsonMissing.of(), - @JsonProperty("user_id") - @ExcludeMissing - private val userId: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val objectId: JsonField, + private val objectType: JsonField, + private val groupId: JsonField, + private val permission: JsonField, + private val restrictObjectType: JsonField, + private val roleId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("object_id") + @ExcludeMissing + objectId: JsonField = JsonMissing.of(), + @JsonProperty("object_type") + @ExcludeMissing + objectType: JsonField = JsonMissing.of(), + @JsonProperty("group_id") @ExcludeMissing groupId: JsonField = JsonMissing.of(), + @JsonProperty("permission") + @ExcludeMissing + permission: JsonField = JsonMissing.of(), + @JsonProperty("restrict_object_type") + @ExcludeMissing + restrictObjectType: JsonField = JsonMissing.of(), + @JsonProperty("role_id") @ExcludeMissing roleId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), + ) : this( + objectId, + objectType, + groupId, + permission, + restrictObjectType, + roleId, + userId, + mutableMapOf(), + ) + /** * The id of the object the ACL applies to * @@ -694,26 +712,15 @@ private constructor( */ @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): AddAcl = apply { - if (validated) { - return@apply - } - - objectId() - objectType() - groupId() - permission() - restrictObjectType() - roleId() - userId() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -920,10 +927,27 @@ private constructor( restrictObjectType, roleId, userId, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): AddAcl = apply { + if (validated) { + return@apply + } + + objectId() + objectType() + groupId() + permission() + restrictObjectType() + roleId() + userId() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -952,35 +976,46 @@ private constructor( * To restrict a grant to a particular sub-object, you may specify `restrict_object_type` in the * ACL, as part of a direct permission grant or as part of a role. */ - @NoAutoDetect class RemoveAcl - @JsonCreator private constructor( - @JsonProperty("object_id") - @ExcludeMissing - private val objectId: JsonField = JsonMissing.of(), - @JsonProperty("object_type") - @ExcludeMissing - private val objectType: JsonField = JsonMissing.of(), - @JsonProperty("group_id") - @ExcludeMissing - private val groupId: JsonField = JsonMissing.of(), - @JsonProperty("permission") - @ExcludeMissing - private val permission: JsonField = JsonMissing.of(), - @JsonProperty("restrict_object_type") - @ExcludeMissing - private val restrictObjectType: JsonField = JsonMissing.of(), - @JsonProperty("role_id") - @ExcludeMissing - private val roleId: JsonField = JsonMissing.of(), - @JsonProperty("user_id") - @ExcludeMissing - private val userId: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val objectId: JsonField, + private val objectType: JsonField, + private val groupId: JsonField, + private val permission: JsonField, + private val restrictObjectType: JsonField, + private val roleId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("object_id") + @ExcludeMissing + objectId: JsonField = JsonMissing.of(), + @JsonProperty("object_type") + @ExcludeMissing + objectType: JsonField = JsonMissing.of(), + @JsonProperty("group_id") @ExcludeMissing groupId: JsonField = JsonMissing.of(), + @JsonProperty("permission") + @ExcludeMissing + permission: JsonField = JsonMissing.of(), + @JsonProperty("restrict_object_type") + @ExcludeMissing + restrictObjectType: JsonField = JsonMissing.of(), + @JsonProperty("role_id") @ExcludeMissing roleId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), + ) : this( + objectId, + objectType, + groupId, + permission, + restrictObjectType, + roleId, + userId, + mutableMapOf(), + ) + /** * The id of the object the ACL applies to * @@ -1098,26 +1133,15 @@ private constructor( */ @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): RemoveAcl = apply { - if (validated) { - return@apply - } - - objectId() - objectType() - groupId() - permission() - restrictObjectType() - roleId() - userId() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1324,10 +1348,27 @@ private constructor( restrictObjectType, roleId, userId, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): RemoveAcl = apply { + if (validated) { + return@apply + } + + objectId() + objectType() + groupId() + permission() + restrictObjectType() + roleId() + userId() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateResponse.kt index ee549d63..f6cd529d 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateResponse.kt @@ -6,31 +6,34 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects -@NoAutoDetect class AclBatchUpdateResponse -@JsonCreator private constructor( - @JsonProperty("added_acls") - @ExcludeMissing - private val addedAcls: JsonField> = JsonMissing.of(), - @JsonProperty("removed_acls") - @ExcludeMissing - private val removedAcls: JsonField> = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val addedAcls: JsonField>, + private val removedAcls: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("added_acls") + @ExcludeMissing + addedAcls: JsonField> = JsonMissing.of(), + @JsonProperty("removed_acls") + @ExcludeMissing + removedAcls: JsonField> = JsonMissing.of(), + ) : this(addedAcls, removedAcls, mutableMapOf()) + /** * An ACL grants a certain permission or role to a certain user or group on an object. * @@ -77,21 +80,15 @@ private constructor( @ExcludeMissing fun _removedAcls(): JsonField> = removedAcls + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): AclBatchUpdateResponse = apply { - if (validated) { - return@apply - } - - addedAcls().forEach { it.validate() } - removedAcls().forEach { it.validate() } - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -229,10 +226,22 @@ private constructor( AclBatchUpdateResponse( checkRequired("addedAcls", addedAcls).map { it.toImmutable() }, checkRequired("removedAcls", removedAcls).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): AclBatchUpdateResponse = apply { + if (validated) { + return@apply + } + + addedAcls().forEach { it.validate() } + removedAcls().forEach { it.validate() } + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclCreateParams.kt index 27d4477a..1925e4ef 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclCreateParams.kt @@ -6,18 +6,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -146,692 +144,708 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body + fun toBuilder() = Builder().from(this) - override fun _headers(): Headers = additionalHeaders + companion object { - override fun _queryParams(): QueryParams = additionalQueryParams + /** + * Returns a mutable builder for constructing an instance of [AclCreateParams]. + * + * The following fields are required: + * ```java + * .objectId() + * .objectType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - /** - * An ACL grants a certain permission or role to a certain user or group on an object. - * - * ACLs are inherited across the object hierarchy. So for example, if a user has read - * permissions on a project, they will also have read permissions on any experiment, dataset, - * etc. created within that project. - * - * To restrict a grant to a particular sub-object, you may specify `restrict_object_type` in the - * ACL, as part of a direct permission grant or as part of a role. - */ - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("object_id") - @ExcludeMissing - private val objectId: JsonField = JsonMissing.of(), - @JsonProperty("object_type") - @ExcludeMissing - private val objectType: JsonField = JsonMissing.of(), - @JsonProperty("group_id") - @ExcludeMissing - private val groupId: JsonField = JsonMissing.of(), - @JsonProperty("permission") - @ExcludeMissing - private val permission: JsonField = JsonMissing.of(), - @JsonProperty("restrict_object_type") - @ExcludeMissing - private val restrictObjectType: JsonField = JsonMissing.of(), - @JsonProperty("role_id") - @ExcludeMissing - private val roleId: JsonField = JsonMissing.of(), - @JsonProperty("user_id") - @ExcludeMissing - private val userId: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + /** A builder for [AclCreateParams]. */ + class Builder internal constructor() { + + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(aclCreateParams: AclCreateParams) = apply { + body = aclCreateParams.body.toBuilder() + additionalHeaders = aclCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = aclCreateParams.additionalQueryParams.toBuilder() + } + + /** The id of the object the ACL applies to */ + fun objectId(objectId: String) = apply { body.objectId(objectId) } /** - * The id of the object the ACL applies to + * Sets [Builder.objectId] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + * You should usually call [Builder.objectId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun objectId(): String = objectId.getRequired("object_id") + fun objectId(objectId: JsonField) = apply { body.objectId(objectId) } + + /** The object type that the ACL applies to */ + fun objectType(objectType: AclObjectType) = apply { body.objectType(objectType) } /** - * The object type that the ACL applies to + * Sets [Builder.objectType] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + * You should usually call [Builder.objectType] with a well-typed [AclObjectType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun objectType(): AclObjectType = objectType.getRequired("object_type") + fun objectType(objectType: JsonField) = apply { body.objectType(objectType) } /** * Id of the group the ACL applies to. Exactly one of `user_id` and `group_id` will be * provided - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). */ - fun groupId(): Optional = Optional.ofNullable(groupId.getNullable("group_id")) + fun groupId(groupId: String?) = apply { body.groupId(groupId) } - /** - * Permission the ACL grants. Exactly one of `permission` and `role_id` will be provided - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun permission(): Optional = - Optional.ofNullable(permission.getNullable("permission")) + /** Alias for calling [Builder.groupId] with `groupId.orElse(null)`. */ + fun groupId(groupId: Optional) = groupId(groupId.getOrNull()) /** - * When setting a permission directly, optionally restricts the permission grant to just the - * specified object type. Cannot be set alongside a `role_id`. + * Sets [Builder.groupId] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.groupId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun restrictObjectType(): Optional = - Optional.ofNullable(restrictObjectType.getNullable("restrict_object_type")) + fun groupId(groupId: JsonField) = apply { body.groupId(groupId) } - /** - * Id of the role the ACL grants. Exactly one of `permission` and `role_id` will be provided - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun roleId(): Optional = Optional.ofNullable(roleId.getNullable("role_id")) + /** Permission the ACL grants. Exactly one of `permission` and `role_id` will be provided */ + fun permission(permission: Permission?) = apply { body.permission(permission) } + + /** Alias for calling [Builder.permission] with `permission.orElse(null)`. */ + fun permission(permission: Optional) = permission(permission.getOrNull()) /** - * Id of the user the ACL applies to. Exactly one of `user_id` and `group_id` will be - * provided + * Sets [Builder.permission] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.permission] with a well-typed [Permission] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) + fun permission(permission: JsonField) = apply { body.permission(permission) } /** - * Returns the raw JSON value of [objectId]. - * - * Unlike [objectId], this method doesn't throw if the JSON field has an unexpected type. + * When setting a permission directly, optionally restricts the permission grant to just the + * specified object type. Cannot be set alongside a `role_id`. */ - @JsonProperty("object_id") @ExcludeMissing fun _objectId(): JsonField = objectId + fun restrictObjectType(restrictObjectType: AclObjectType?) = apply { + body.restrictObjectType(restrictObjectType) + } /** - * Returns the raw JSON value of [objectType]. - * - * Unlike [objectType], this method doesn't throw if the JSON field has an unexpected type. + * Alias for calling [Builder.restrictObjectType] with `restrictObjectType.orElse(null)`. */ - @JsonProperty("object_type") - @ExcludeMissing - fun _objectType(): JsonField = objectType + fun restrictObjectType(restrictObjectType: Optional) = + restrictObjectType(restrictObjectType.getOrNull()) /** - * Returns the raw JSON value of [groupId]. + * Sets [Builder.restrictObjectType] to an arbitrary JSON value. * - * Unlike [groupId], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.restrictObjectType] with a well-typed [AclObjectType] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. */ - @JsonProperty("group_id") @ExcludeMissing fun _groupId(): JsonField = groupId + fun restrictObjectType(restrictObjectType: JsonField) = apply { + body.restrictObjectType(restrictObjectType) + } /** - * Returns the raw JSON value of [permission]. - * - * Unlike [permission], this method doesn't throw if the JSON field has an unexpected type. + * Id of the role the ACL grants. Exactly one of `permission` and `role_id` will be provided */ - @JsonProperty("permission") - @ExcludeMissing - fun _permission(): JsonField = permission + fun roleId(roleId: String?) = apply { body.roleId(roleId) } + + /** Alias for calling [Builder.roleId] with `roleId.orElse(null)`. */ + fun roleId(roleId: Optional) = roleId(roleId.getOrNull()) /** - * Returns the raw JSON value of [restrictObjectType]. + * Sets [Builder.roleId] to an arbitrary JSON value. * - * Unlike [restrictObjectType], this method doesn't throw if the JSON field has an - * unexpected type. + * You should usually call [Builder.roleId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("restrict_object_type") - @ExcludeMissing - fun _restrictObjectType(): JsonField = restrictObjectType + fun roleId(roleId: JsonField) = apply { body.roleId(roleId) } /** - * Returns the raw JSON value of [roleId]. - * - * Unlike [roleId], this method doesn't throw if the JSON field has an unexpected type. + * Id of the user the ACL applies to. Exactly one of `user_id` and `group_id` will be + * provided */ - @JsonProperty("role_id") @ExcludeMissing fun _roleId(): JsonField = roleId + fun userId(userId: String?) = apply { body.userId(userId) } + + /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ + fun userId(userId: Optional) = userId(userId.getOrNull()) /** - * Returns the raw JSON value of [userId]. + * Sets [Builder.userId] to an arbitrary JSON value. * - * Unlike [userId], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.userId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + fun userId(userId: JsonField) = apply { body.userId(userId) } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } - private var validated: Boolean = false + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } - fun validate(): Body = apply { - if (validated) { - return@apply + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) } - objectId() - objectType() - groupId() - permission() - restrictObjectType() - roleId() - userId() - validated = true + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) } - fun toBuilder() = Builder().from(this) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - companion object { + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .objectId() - * .objectType() - * ``` - */ - @JvmStatic fun builder() = Builder() + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - /** A builder for [Body]. */ - class Builder internal constructor() { + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - private var objectId: JsonField? = null - private var objectType: JsonField? = null - private var groupId: JsonField = JsonMissing.of() - private var permission: JsonField = JsonMissing.of() - private var restrictObjectType: JsonField = JsonMissing.of() - private var roleId: JsonField = JsonMissing.of() - private var userId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - @JvmSynthetic - internal fun from(body: Body) = apply { - objectId = body.objectId - objectType = body.objectType - groupId = body.groupId - permission = body.permission - restrictObjectType = body.restrictObjectType - roleId = body.roleId - userId = body.userId - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** The id of the object the ACL applies to */ - fun objectId(objectId: String) = objectId(JsonField.of(objectId)) - - /** - * Sets [Builder.objectId] to an arbitrary JSON value. - * - * You should usually call [Builder.objectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun objectId(objectId: JsonField) = apply { this.objectId = objectId } - - /** The object type that the ACL applies to */ - fun objectType(objectType: AclObjectType) = objectType(JsonField.of(objectType)) - - /** - * Sets [Builder.objectType] to an arbitrary JSON value. - * - * You should usually call [Builder.objectType] with a well-typed [AclObjectType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun objectType(objectType: JsonField) = apply { - this.objectType = objectType - } - - /** - * Id of the group the ACL applies to. Exactly one of `user_id` and `group_id` will be - * provided - */ - fun groupId(groupId: String?) = groupId(JsonField.ofNullable(groupId)) - - /** Alias for calling [Builder.groupId] with `groupId.orElse(null)`. */ - fun groupId(groupId: Optional) = groupId(groupId.getOrNull()) - - /** - * Sets [Builder.groupId] to an arbitrary JSON value. - * - * You should usually call [Builder.groupId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun groupId(groupId: JsonField) = apply { this.groupId = groupId } - - /** - * Permission the ACL grants. Exactly one of `permission` and `role_id` will be provided - */ - fun permission(permission: Permission?) = permission(JsonField.ofNullable(permission)) - - /** Alias for calling [Builder.permission] with `permission.orElse(null)`. */ - fun permission(permission: Optional) = permission(permission.getOrNull()) - - /** - * Sets [Builder.permission] to an arbitrary JSON value. - * - * You should usually call [Builder.permission] with a well-typed [Permission] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun permission(permission: JsonField) = apply { - this.permission = permission - } - - /** - * When setting a permission directly, optionally restricts the permission grant to just - * the specified object type. Cannot be set alongside a `role_id`. - */ - fun restrictObjectType(restrictObjectType: AclObjectType?) = - restrictObjectType(JsonField.ofNullable(restrictObjectType)) - - /** - * Alias for calling [Builder.restrictObjectType] with - * `restrictObjectType.orElse(null)`. - */ - fun restrictObjectType(restrictObjectType: Optional) = - restrictObjectType(restrictObjectType.getOrNull()) - - /** - * Sets [Builder.restrictObjectType] to an arbitrary JSON value. - * - * You should usually call [Builder.restrictObjectType] with a well-typed - * [AclObjectType] value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun restrictObjectType(restrictObjectType: JsonField) = apply { - this.restrictObjectType = restrictObjectType - } - - /** - * Id of the role the ACL grants. Exactly one of `permission` and `role_id` will be - * provided - */ - fun roleId(roleId: String?) = roleId(JsonField.ofNullable(roleId)) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** Alias for calling [Builder.roleId] with `roleId.orElse(null)`. */ - fun roleId(roleId: Optional) = roleId(roleId.getOrNull()) + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - /** - * Sets [Builder.roleId] to an arbitrary JSON value. - * - * You should usually call [Builder.roleId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun roleId(roleId: JsonField) = apply { this.roleId = roleId } + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** - * Id of the user the ACL applies to. Exactly one of `user_id` and `group_id` will be - * provided - */ - fun userId(userId: String?) = userId(JsonField.ofNullable(userId)) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ - fun userId(userId: Optional) = userId(userId.getOrNull()) + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Sets [Builder.userId] to an arbitrary JSON value. - * - * You should usually call [Builder.userId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun userId(userId: JsonField) = apply { this.userId = userId } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .objectId() - * .objectType() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("objectId", objectId), - checkRequired("objectType", objectType), - groupId, - permission, - restrictObjectType, - roleId, - userId, - additionalProperties.toImmutable(), - ) + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - return /* spotless:off */ other is Body && objectId == other.objectId && objectType == other.objectType && groupId == other.groupId && permission == other.permission && restrictObjectType == other.restrictObjectType && roleId == other.roleId && userId == other.userId && additionalProperties == other.additionalProperties /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(objectId, objectType, groupId, permission, restrictObjectType, roleId, userId, additionalProperties) } - /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } - override fun hashCode(): Int = hashCode + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - override fun toString() = - "Body{objectId=$objectId, objectType=$objectType, groupId=$groupId, permission=$permission, restrictObjectType=$restrictObjectType, roleId=$roleId, userId=$userId, additionalProperties=$additionalProperties}" - } + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - fun toBuilder() = Builder().from(this) + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - companion object { + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } /** - * Returns a mutable builder for constructing an instance of [AclCreateParams]. + * Returns an immutable instance of [AclCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java * .objectId() * .objectType() * ``` + * + * @throws IllegalStateException if any required field is unset. */ - @JvmStatic fun builder() = Builder() + fun build(): AclCreateParams = + AclCreateParams(body.build(), additionalHeaders.build(), additionalQueryParams.build()) } - /** A builder for [AclCreateParams]. */ - @NoAutoDetect - class Builder internal constructor() { + @JvmSynthetic internal fun _body(): Body = body - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun from(aclCreateParams: AclCreateParams) = apply { - body = aclCreateParams.body.toBuilder() - additionalHeaders = aclCreateParams.additionalHeaders.toBuilder() - additionalQueryParams = aclCreateParams.additionalQueryParams.toBuilder() - } + override fun _queryParams(): QueryParams = additionalQueryParams - /** The id of the object the ACL applies to */ - fun objectId(objectId: String) = apply { body.objectId(objectId) } + /** + * An ACL grants a certain permission or role to a certain user or group on an object. + * + * ACLs are inherited across the object hierarchy. So for example, if a user has read + * permissions on a project, they will also have read permissions on any experiment, dataset, + * etc. created within that project. + * + * To restrict a grant to a particular sub-object, you may specify `restrict_object_type` in the + * ACL, as part of a direct permission grant or as part of a role. + */ + class Body + private constructor( + private val objectId: JsonField, + private val objectType: JsonField, + private val groupId: JsonField, + private val permission: JsonField, + private val restrictObjectType: JsonField, + private val roleId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("object_id") + @ExcludeMissing + objectId: JsonField = JsonMissing.of(), + @JsonProperty("object_type") + @ExcludeMissing + objectType: JsonField = JsonMissing.of(), + @JsonProperty("group_id") @ExcludeMissing groupId: JsonField = JsonMissing.of(), + @JsonProperty("permission") + @ExcludeMissing + permission: JsonField = JsonMissing.of(), + @JsonProperty("restrict_object_type") + @ExcludeMissing + restrictObjectType: JsonField = JsonMissing.of(), + @JsonProperty("role_id") @ExcludeMissing roleId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), + ) : this( + objectId, + objectType, + groupId, + permission, + restrictObjectType, + roleId, + userId, + mutableMapOf(), + ) /** - * Sets [Builder.objectId] to an arbitrary JSON value. + * The id of the object the ACL applies to * - * You should usually call [Builder.objectId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun objectId(objectId: JsonField) = apply { body.objectId(objectId) } - - /** The object type that the ACL applies to */ - fun objectType(objectType: AclObjectType) = apply { body.objectType(objectType) } + fun objectId(): String = objectId.getRequired("object_id") /** - * Sets [Builder.objectType] to an arbitrary JSON value. + * The object type that the ACL applies to * - * You should usually call [Builder.objectType] with a well-typed [AclObjectType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun objectType(objectType: JsonField) = apply { body.objectType(objectType) } + fun objectType(): AclObjectType = objectType.getRequired("object_type") /** * Id of the group the ACL applies to. Exactly one of `user_id` and `group_id` will be * provided + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun groupId(groupId: String?) = apply { body.groupId(groupId) } - - /** Alias for calling [Builder.groupId] with `groupId.orElse(null)`. */ - fun groupId(groupId: Optional) = groupId(groupId.getOrNull()) + fun groupId(): Optional = Optional.ofNullable(groupId.getNullable("group_id")) /** - * Sets [Builder.groupId] to an arbitrary JSON value. + * Permission the ACL grants. Exactly one of `permission` and `role_id` will be provided * - * You should usually call [Builder.groupId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun groupId(groupId: JsonField) = apply { body.groupId(groupId) } - - /** Permission the ACL grants. Exactly one of `permission` and `role_id` will be provided */ - fun permission(permission: Permission?) = apply { body.permission(permission) } - - /** Alias for calling [Builder.permission] with `permission.orElse(null)`. */ - fun permission(permission: Optional) = permission(permission.getOrNull()) + fun permission(): Optional = + Optional.ofNullable(permission.getNullable("permission")) /** - * Sets [Builder.permission] to an arbitrary JSON value. + * When setting a permission directly, optionally restricts the permission grant to just the + * specified object type. Cannot be set alongside a `role_id`. * - * You should usually call [Builder.permission] with a well-typed [Permission] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun permission(permission: JsonField) = apply { body.permission(permission) } + fun restrictObjectType(): Optional = + Optional.ofNullable(restrictObjectType.getNullable("restrict_object_type")) /** - * When setting a permission directly, optionally restricts the permission grant to just the - * specified object type. Cannot be set alongside a `role_id`. + * Id of the role the ACL grants. Exactly one of `permission` and `role_id` will be provided + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun restrictObjectType(restrictObjectType: AclObjectType?) = apply { - body.restrictObjectType(restrictObjectType) - } + fun roleId(): Optional = Optional.ofNullable(roleId.getNullable("role_id")) /** - * Alias for calling [Builder.restrictObjectType] with `restrictObjectType.orElse(null)`. + * Id of the user the ACL applies to. Exactly one of `user_id` and `group_id` will be + * provided + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun restrictObjectType(restrictObjectType: Optional) = - restrictObjectType(restrictObjectType.getOrNull()) + fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) /** - * Sets [Builder.restrictObjectType] to an arbitrary JSON value. + * Returns the raw JSON value of [objectId]. * - * You should usually call [Builder.restrictObjectType] with a well-typed [AclObjectType] - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * Unlike [objectId], this method doesn't throw if the JSON field has an unexpected type. */ - fun restrictObjectType(restrictObjectType: JsonField) = apply { - body.restrictObjectType(restrictObjectType) - } + @JsonProperty("object_id") @ExcludeMissing fun _objectId(): JsonField = objectId /** - * Id of the role the ACL grants. Exactly one of `permission` and `role_id` will be provided + * Returns the raw JSON value of [objectType]. + * + * Unlike [objectType], this method doesn't throw if the JSON field has an unexpected type. */ - fun roleId(roleId: String?) = apply { body.roleId(roleId) } + @JsonProperty("object_type") + @ExcludeMissing + fun _objectType(): JsonField = objectType - /** Alias for calling [Builder.roleId] with `roleId.orElse(null)`. */ - fun roleId(roleId: Optional) = roleId(roleId.getOrNull()) + /** + * Returns the raw JSON value of [groupId]. + * + * Unlike [groupId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("group_id") @ExcludeMissing fun _groupId(): JsonField = groupId /** - * Sets [Builder.roleId] to an arbitrary JSON value. + * Returns the raw JSON value of [permission]. * - * You should usually call [Builder.roleId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [permission], this method doesn't throw if the JSON field has an unexpected type. */ - fun roleId(roleId: JsonField) = apply { body.roleId(roleId) } + @JsonProperty("permission") + @ExcludeMissing + fun _permission(): JsonField = permission /** - * Id of the user the ACL applies to. Exactly one of `user_id` and `group_id` will be - * provided + * Returns the raw JSON value of [restrictObjectType]. + * + * Unlike [restrictObjectType], this method doesn't throw if the JSON field has an + * unexpected type. */ - fun userId(userId: String?) = apply { body.userId(userId) } + @JsonProperty("restrict_object_type") + @ExcludeMissing + fun _restrictObjectType(): JsonField = restrictObjectType - /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ - fun userId(userId: Optional) = userId(userId.getOrNull()) + /** + * Returns the raw JSON value of [roleId]. + * + * Unlike [roleId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("role_id") @ExcludeMissing fun _roleId(): JsonField = roleId /** - * Sets [Builder.userId] to an arbitrary JSON value. + * Returns the raw JSON value of [userId]. * - * You should usually call [Builder.userId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected type. */ - fun userId(userId: JsonField) = apply { body.userId(userId) } + @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .objectId() + * .objectType() + * ``` + */ + @JvmStatic fun builder() = Builder() } - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var objectId: JsonField? = null + private var objectType: JsonField? = null + private var groupId: JsonField = JsonMissing.of() + private var permission: JsonField = JsonMissing.of() + private var restrictObjectType: JsonField = JsonMissing.of() + private var roleId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + objectId = body.objectId + objectType = body.objectType + groupId = body.groupId + permission = body.permission + restrictObjectType = body.restrictObjectType + roleId = body.roleId + userId = body.userId + additionalProperties = body.additionalProperties.toMutableMap() } - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + /** The id of the object the ACL applies to */ + fun objectId(objectId: String) = objectId(JsonField.of(objectId)) - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } + /** + * Sets [Builder.objectId] to an arbitrary JSON value. + * + * You should usually call [Builder.objectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun objectId(objectId: JsonField) = apply { this.objectId = objectId } - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** The object type that the ACL applies to */ + fun objectType(objectType: AclObjectType) = objectType(JsonField.of(objectType)) - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * Sets [Builder.objectType] to an arbitrary JSON value. + * + * You should usually call [Builder.objectType] with a well-typed [AclObjectType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun objectType(objectType: JsonField) = apply { + this.objectType = objectType + } - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } + /** + * Id of the group the ACL applies to. Exactly one of `user_id` and `group_id` will be + * provided + */ + fun groupId(groupId: String?) = groupId(JsonField.ofNullable(groupId)) - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } + /** Alias for calling [Builder.groupId] with `groupId.orElse(null)`. */ + fun groupId(groupId: Optional) = groupId(groupId.getOrNull()) - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** + * Sets [Builder.groupId] to an arbitrary JSON value. + * + * You should usually call [Builder.groupId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun groupId(groupId: JsonField) = apply { this.groupId = groupId } - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** + * Permission the ACL grants. Exactly one of `permission` and `role_id` will be provided + */ + fun permission(permission: Permission?) = permission(JsonField.ofNullable(permission)) - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } + /** Alias for calling [Builder.permission] with `permission.orElse(null)`. */ + fun permission(permission: Optional) = permission(permission.getOrNull()) - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } + /** + * Sets [Builder.permission] to an arbitrary JSON value. + * + * You should usually call [Builder.permission] with a well-typed [Permission] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun permission(permission: JsonField) = apply { + this.permission = permission + } - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** + * When setting a permission directly, optionally restricts the permission grant to just + * the specified object type. Cannot be set alongside a `role_id`. + */ + fun restrictObjectType(restrictObjectType: AclObjectType?) = + restrictObjectType(JsonField.ofNullable(restrictObjectType)) - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** + * Alias for calling [Builder.restrictObjectType] with + * `restrictObjectType.orElse(null)`. + */ + fun restrictObjectType(restrictObjectType: Optional) = + restrictObjectType(restrictObjectType.getOrNull()) - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + /** + * Sets [Builder.restrictObjectType] to an arbitrary JSON value. + * + * You should usually call [Builder.restrictObjectType] with a well-typed + * [AclObjectType] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun restrictObjectType(restrictObjectType: JsonField) = apply { + this.restrictObjectType = restrictObjectType + } - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } + /** + * Id of the role the ACL grants. Exactly one of `permission` and `role_id` will be + * provided + */ + fun roleId(roleId: String?) = roleId(JsonField.ofNullable(roleId)) - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + /** Alias for calling [Builder.roleId] with `roleId.orElse(null)`. */ + fun roleId(roleId: Optional) = roleId(roleId.getOrNull()) - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + /** + * Sets [Builder.roleId] to an arbitrary JSON value. + * + * You should usually call [Builder.roleId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun roleId(roleId: JsonField) = apply { this.roleId = roleId } - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } + /** + * Id of the user the ACL applies to. Exactly one of `user_id` and `group_id` will be + * provided + */ + fun userId(userId: String?) = userId(JsonField.ofNullable(userId)) - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) - } + /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ + fun userId(userId: Optional) = userId(userId.getOrNull()) - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } + /** + * Sets [Builder.userId] to an arbitrary JSON value. + * + * You should usually call [Builder.userId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun userId(userId: JsonField) = apply { this.userId = userId } - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) } - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .objectId() + * .objectType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("objectId", objectId), + checkRequired("objectType", objectType), + groupId, + permission, + restrictObjectType, + roleId, + userId, + additionalProperties.toMutableMap(), + ) } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply } - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + objectId() + objectType() + groupId() + permission() + restrictObjectType() + roleId() + userId() + validated = true + } - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && objectId == other.objectId && objectType == other.objectType && groupId == other.groupId && permission == other.permission && restrictObjectType == other.restrictObjectType && roleId == other.roleId && userId == other.userId && additionalProperties == other.additionalProperties /* spotless:on */ } - /** - * Returns an immutable instance of [AclCreateParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .objectId() - * .objectType() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): AclCreateParams = - AclCreateParams(body.build(), additionalHeaders.build(), additionalQueryParams.build()) + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(objectId, objectType, groupId, permission, restrictObjectType, roleId, userId, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{objectId=$objectId, objectType=$objectType, groupId=$groupId, permission=$permission, restrictObjectType=$restrictObjectType, roleId=$roleId, userId=$userId, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclDeleteParams.kt index a0eda97b..5a35222f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclDeleteParams.kt @@ -2,13 +2,15 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.toImmutable +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import java.util.Collections import java.util.Objects import java.util.Optional @@ -18,7 +20,7 @@ private constructor( private val aclId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: Map, + private val additionalBodyProperties: MutableMap, ) : Params { /** Acl id */ @@ -28,21 +30,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _additionalBodyProperties(): Map = additionalBodyProperties - - @JvmSynthetic - internal fun _body(): Optional> = - Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - - fun _pathParam(index: Int): String = - when (index) { - 0 -> aclId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders + @JsonAnySetter + private fun putAdditionalBodyProperty(key: String, value: JsonValue) { + additionalBodyProperties.put(key, value) + } - override fun _queryParams(): QueryParams = additionalQueryParams + @JsonAnyGetter + @ExcludeMissing + fun _additionalBodyProperties(): Map = + Collections.unmodifiableMap(additionalBodyProperties) fun toBuilder() = Builder().from(this) @@ -60,7 +56,6 @@ private constructor( } /** A builder for [AclDeleteParams]. */ - @NoAutoDetect class Builder internal constructor() { private var aclId: String? = null @@ -216,10 +211,24 @@ private constructor( checkRequired("aclId", aclId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toImmutable(), + additionalBodyProperties.toMutableMap(), ) } + @JvmSynthetic + internal fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> aclId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParams.kt index 5f778de3..f2c9e1ab 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParams.kt @@ -6,18 +6,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -143,696 +141,712 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body + fun toBuilder() = Builder().from(this) - override fun _headers(): Headers = additionalHeaders + companion object { - override fun _queryParams(): QueryParams = additionalQueryParams + /** + * Returns a mutable builder for constructing an instance of [AclFindAndDeleteParams]. + * + * The following fields are required: + * ```java + * .objectId() + * .objectType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - /** - * An ACL grants a certain permission or role to a certain user or group on an object. - * - * ACLs are inherited across the object hierarchy. So for example, if a user has read - * permissions on a project, they will also have read permissions on any experiment, dataset, - * etc. created within that project. - * - * To restrict a grant to a particular sub-object, you may specify `restrict_object_type` in the - * ACL, as part of a direct permission grant or as part of a role. - */ - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("object_id") - @ExcludeMissing - private val objectId: JsonField = JsonMissing.of(), - @JsonProperty("object_type") - @ExcludeMissing - private val objectType: JsonField = JsonMissing.of(), - @JsonProperty("group_id") - @ExcludeMissing - private val groupId: JsonField = JsonMissing.of(), - @JsonProperty("permission") - @ExcludeMissing - private val permission: JsonField = JsonMissing.of(), - @JsonProperty("restrict_object_type") - @ExcludeMissing - private val restrictObjectType: JsonField = JsonMissing.of(), - @JsonProperty("role_id") - @ExcludeMissing - private val roleId: JsonField = JsonMissing.of(), - @JsonProperty("user_id") - @ExcludeMissing - private val userId: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + /** A builder for [AclFindAndDeleteParams]. */ + class Builder internal constructor() { + + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(aclFindAndDeleteParams: AclFindAndDeleteParams) = apply { + body = aclFindAndDeleteParams.body.toBuilder() + additionalHeaders = aclFindAndDeleteParams.additionalHeaders.toBuilder() + additionalQueryParams = aclFindAndDeleteParams.additionalQueryParams.toBuilder() + } + + /** The id of the object the ACL applies to */ + fun objectId(objectId: String) = apply { body.objectId(objectId) } /** - * The id of the object the ACL applies to + * Sets [Builder.objectId] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + * You should usually call [Builder.objectId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun objectId(): String = objectId.getRequired("object_id") + fun objectId(objectId: JsonField) = apply { body.objectId(objectId) } + + /** The object type that the ACL applies to */ + fun objectType(objectType: AclObjectType) = apply { body.objectType(objectType) } /** - * The object type that the ACL applies to + * Sets [Builder.objectType] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + * You should usually call [Builder.objectType] with a well-typed [AclObjectType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun objectType(): AclObjectType = objectType.getRequired("object_type") + fun objectType(objectType: JsonField) = apply { body.objectType(objectType) } /** * Id of the group the ACL applies to. Exactly one of `user_id` and `group_id` will be * provided - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). */ - fun groupId(): Optional = Optional.ofNullable(groupId.getNullable("group_id")) + fun groupId(groupId: String?) = apply { body.groupId(groupId) } - /** - * Permission the ACL grants. Exactly one of `permission` and `role_id` will be provided - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun permission(): Optional = - Optional.ofNullable(permission.getNullable("permission")) + /** Alias for calling [Builder.groupId] with `groupId.orElse(null)`. */ + fun groupId(groupId: Optional) = groupId(groupId.getOrNull()) /** - * When setting a permission directly, optionally restricts the permission grant to just the - * specified object type. Cannot be set alongside a `role_id`. + * Sets [Builder.groupId] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.groupId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun restrictObjectType(): Optional = - Optional.ofNullable(restrictObjectType.getNullable("restrict_object_type")) + fun groupId(groupId: JsonField) = apply { body.groupId(groupId) } - /** - * Id of the role the ACL grants. Exactly one of `permission` and `role_id` will be provided - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun roleId(): Optional = Optional.ofNullable(roleId.getNullable("role_id")) + /** Permission the ACL grants. Exactly one of `permission` and `role_id` will be provided */ + fun permission(permission: Permission?) = apply { body.permission(permission) } + + /** Alias for calling [Builder.permission] with `permission.orElse(null)`. */ + fun permission(permission: Optional) = permission(permission.getOrNull()) /** - * Id of the user the ACL applies to. Exactly one of `user_id` and `group_id` will be - * provided + * Sets [Builder.permission] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.permission] with a well-typed [Permission] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) + fun permission(permission: JsonField) = apply { body.permission(permission) } /** - * Returns the raw JSON value of [objectId]. - * - * Unlike [objectId], this method doesn't throw if the JSON field has an unexpected type. + * When setting a permission directly, optionally restricts the permission grant to just the + * specified object type. Cannot be set alongside a `role_id`. */ - @JsonProperty("object_id") @ExcludeMissing fun _objectId(): JsonField = objectId + fun restrictObjectType(restrictObjectType: AclObjectType?) = apply { + body.restrictObjectType(restrictObjectType) + } /** - * Returns the raw JSON value of [objectType]. - * - * Unlike [objectType], this method doesn't throw if the JSON field has an unexpected type. + * Alias for calling [Builder.restrictObjectType] with `restrictObjectType.orElse(null)`. */ - @JsonProperty("object_type") - @ExcludeMissing - fun _objectType(): JsonField = objectType + fun restrictObjectType(restrictObjectType: Optional) = + restrictObjectType(restrictObjectType.getOrNull()) /** - * Returns the raw JSON value of [groupId]. + * Sets [Builder.restrictObjectType] to an arbitrary JSON value. * - * Unlike [groupId], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.restrictObjectType] with a well-typed [AclObjectType] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. */ - @JsonProperty("group_id") @ExcludeMissing fun _groupId(): JsonField = groupId + fun restrictObjectType(restrictObjectType: JsonField) = apply { + body.restrictObjectType(restrictObjectType) + } /** - * Returns the raw JSON value of [permission]. - * - * Unlike [permission], this method doesn't throw if the JSON field has an unexpected type. + * Id of the role the ACL grants. Exactly one of `permission` and `role_id` will be provided */ - @JsonProperty("permission") - @ExcludeMissing - fun _permission(): JsonField = permission + fun roleId(roleId: String?) = apply { body.roleId(roleId) } + + /** Alias for calling [Builder.roleId] with `roleId.orElse(null)`. */ + fun roleId(roleId: Optional) = roleId(roleId.getOrNull()) /** - * Returns the raw JSON value of [restrictObjectType]. + * Sets [Builder.roleId] to an arbitrary JSON value. * - * Unlike [restrictObjectType], this method doesn't throw if the JSON field has an - * unexpected type. + * You should usually call [Builder.roleId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("restrict_object_type") - @ExcludeMissing - fun _restrictObjectType(): JsonField = restrictObjectType + fun roleId(roleId: JsonField) = apply { body.roleId(roleId) } /** - * Returns the raw JSON value of [roleId]. - * - * Unlike [roleId], this method doesn't throw if the JSON field has an unexpected type. + * Id of the user the ACL applies to. Exactly one of `user_id` and `group_id` will be + * provided */ - @JsonProperty("role_id") @ExcludeMissing fun _roleId(): JsonField = roleId + fun userId(userId: String?) = apply { body.userId(userId) } + + /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ + fun userId(userId: Optional) = userId(userId.getOrNull()) /** - * Returns the raw JSON value of [userId]. + * Sets [Builder.userId] to an arbitrary JSON value. * - * Unlike [userId], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.userId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + fun userId(userId: JsonField) = apply { body.userId(userId) } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } - private var validated: Boolean = false + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } - fun validate(): Body = apply { - if (validated) { - return@apply + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) } - objectId() - objectType() - groupId() - permission() - restrictObjectType() - roleId() - userId() - validated = true + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) } - fun toBuilder() = Builder().from(this) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - companion object { + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .objectId() - * .objectType() - * ``` - */ - @JvmStatic fun builder() = Builder() + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - /** A builder for [Body]. */ - class Builder internal constructor() { + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - private var objectId: JsonField? = null - private var objectType: JsonField? = null - private var groupId: JsonField = JsonMissing.of() - private var permission: JsonField = JsonMissing.of() - private var restrictObjectType: JsonField = JsonMissing.of() - private var roleId: JsonField = JsonMissing.of() - private var userId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - @JvmSynthetic - internal fun from(body: Body) = apply { - objectId = body.objectId - objectType = body.objectType - groupId = body.groupId - permission = body.permission - restrictObjectType = body.restrictObjectType - roleId = body.roleId - userId = body.userId - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** The id of the object the ACL applies to */ - fun objectId(objectId: String) = objectId(JsonField.of(objectId)) - - /** - * Sets [Builder.objectId] to an arbitrary JSON value. - * - * You should usually call [Builder.objectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun objectId(objectId: JsonField) = apply { this.objectId = objectId } - - /** The object type that the ACL applies to */ - fun objectType(objectType: AclObjectType) = objectType(JsonField.of(objectType)) - - /** - * Sets [Builder.objectType] to an arbitrary JSON value. - * - * You should usually call [Builder.objectType] with a well-typed [AclObjectType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun objectType(objectType: JsonField) = apply { - this.objectType = objectType - } - - /** - * Id of the group the ACL applies to. Exactly one of `user_id` and `group_id` will be - * provided - */ - fun groupId(groupId: String?) = groupId(JsonField.ofNullable(groupId)) - - /** Alias for calling [Builder.groupId] with `groupId.orElse(null)`. */ - fun groupId(groupId: Optional) = groupId(groupId.getOrNull()) - - /** - * Sets [Builder.groupId] to an arbitrary JSON value. - * - * You should usually call [Builder.groupId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun groupId(groupId: JsonField) = apply { this.groupId = groupId } - - /** - * Permission the ACL grants. Exactly one of `permission` and `role_id` will be provided - */ - fun permission(permission: Permission?) = permission(JsonField.ofNullable(permission)) - - /** Alias for calling [Builder.permission] with `permission.orElse(null)`. */ - fun permission(permission: Optional) = permission(permission.getOrNull()) - - /** - * Sets [Builder.permission] to an arbitrary JSON value. - * - * You should usually call [Builder.permission] with a well-typed [Permission] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun permission(permission: JsonField) = apply { - this.permission = permission - } - - /** - * When setting a permission directly, optionally restricts the permission grant to just - * the specified object type. Cannot be set alongside a `role_id`. - */ - fun restrictObjectType(restrictObjectType: AclObjectType?) = - restrictObjectType(JsonField.ofNullable(restrictObjectType)) - - /** - * Alias for calling [Builder.restrictObjectType] with - * `restrictObjectType.orElse(null)`. - */ - fun restrictObjectType(restrictObjectType: Optional) = - restrictObjectType(restrictObjectType.getOrNull()) - - /** - * Sets [Builder.restrictObjectType] to an arbitrary JSON value. - * - * You should usually call [Builder.restrictObjectType] with a well-typed - * [AclObjectType] value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun restrictObjectType(restrictObjectType: JsonField) = apply { - this.restrictObjectType = restrictObjectType - } - - /** - * Id of the role the ACL grants. Exactly one of `permission` and `role_id` will be - * provided - */ - fun roleId(roleId: String?) = roleId(JsonField.ofNullable(roleId)) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** Alias for calling [Builder.roleId] with `roleId.orElse(null)`. */ - fun roleId(roleId: Optional) = roleId(roleId.getOrNull()) + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - /** - * Sets [Builder.roleId] to an arbitrary JSON value. - * - * You should usually call [Builder.roleId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun roleId(roleId: JsonField) = apply { this.roleId = roleId } + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** - * Id of the user the ACL applies to. Exactly one of `user_id` and `group_id` will be - * provided - */ - fun userId(userId: String?) = userId(JsonField.ofNullable(userId)) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ - fun userId(userId: Optional) = userId(userId.getOrNull()) + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Sets [Builder.userId] to an arbitrary JSON value. - * - * You should usually call [Builder.userId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun userId(userId: JsonField) = apply { this.userId = userId } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .objectId() - * .objectType() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("objectId", objectId), - checkRequired("objectType", objectType), - groupId, - permission, - restrictObjectType, - roleId, - userId, - additionalProperties.toImmutable(), - ) + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - return /* spotless:off */ other is Body && objectId == other.objectId && objectType == other.objectType && groupId == other.groupId && permission == other.permission && restrictObjectType == other.restrictObjectType && roleId == other.roleId && userId == other.userId && additionalProperties == other.additionalProperties /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(objectId, objectType, groupId, permission, restrictObjectType, roleId, userId, additionalProperties) } - /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } - override fun hashCode(): Int = hashCode + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - override fun toString() = - "Body{objectId=$objectId, objectType=$objectType, groupId=$groupId, permission=$permission, restrictObjectType=$restrictObjectType, roleId=$roleId, userId=$userId, additionalProperties=$additionalProperties}" - } + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - fun toBuilder() = Builder().from(this) + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - companion object { + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } /** - * Returns a mutable builder for constructing an instance of [AclFindAndDeleteParams]. + * Returns an immutable instance of [AclFindAndDeleteParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java * .objectId() * .objectType() * ``` + * + * @throws IllegalStateException if any required field is unset. */ - @JvmStatic fun builder() = Builder() + fun build(): AclFindAndDeleteParams = + AclFindAndDeleteParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) } - /** A builder for [AclFindAndDeleteParams]. */ - @NoAutoDetect - class Builder internal constructor() { + @JvmSynthetic internal fun _body(): Body = body - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun from(aclFindAndDeleteParams: AclFindAndDeleteParams) = apply { - body = aclFindAndDeleteParams.body.toBuilder() - additionalHeaders = aclFindAndDeleteParams.additionalHeaders.toBuilder() - additionalQueryParams = aclFindAndDeleteParams.additionalQueryParams.toBuilder() - } + override fun _queryParams(): QueryParams = additionalQueryParams - /** The id of the object the ACL applies to */ - fun objectId(objectId: String) = apply { body.objectId(objectId) } + /** + * An ACL grants a certain permission or role to a certain user or group on an object. + * + * ACLs are inherited across the object hierarchy. So for example, if a user has read + * permissions on a project, they will also have read permissions on any experiment, dataset, + * etc. created within that project. + * + * To restrict a grant to a particular sub-object, you may specify `restrict_object_type` in the + * ACL, as part of a direct permission grant or as part of a role. + */ + class Body + private constructor( + private val objectId: JsonField, + private val objectType: JsonField, + private val groupId: JsonField, + private val permission: JsonField, + private val restrictObjectType: JsonField, + private val roleId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("object_id") + @ExcludeMissing + objectId: JsonField = JsonMissing.of(), + @JsonProperty("object_type") + @ExcludeMissing + objectType: JsonField = JsonMissing.of(), + @JsonProperty("group_id") @ExcludeMissing groupId: JsonField = JsonMissing.of(), + @JsonProperty("permission") + @ExcludeMissing + permission: JsonField = JsonMissing.of(), + @JsonProperty("restrict_object_type") + @ExcludeMissing + restrictObjectType: JsonField = JsonMissing.of(), + @JsonProperty("role_id") @ExcludeMissing roleId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), + ) : this( + objectId, + objectType, + groupId, + permission, + restrictObjectType, + roleId, + userId, + mutableMapOf(), + ) /** - * Sets [Builder.objectId] to an arbitrary JSON value. + * The id of the object the ACL applies to * - * You should usually call [Builder.objectId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun objectId(objectId: JsonField) = apply { body.objectId(objectId) } - - /** The object type that the ACL applies to */ - fun objectType(objectType: AclObjectType) = apply { body.objectType(objectType) } + fun objectId(): String = objectId.getRequired("object_id") /** - * Sets [Builder.objectType] to an arbitrary JSON value. + * The object type that the ACL applies to * - * You should usually call [Builder.objectType] with a well-typed [AclObjectType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun objectType(objectType: JsonField) = apply { body.objectType(objectType) } + fun objectType(): AclObjectType = objectType.getRequired("object_type") /** * Id of the group the ACL applies to. Exactly one of `user_id` and `group_id` will be * provided + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun groupId(groupId: String?) = apply { body.groupId(groupId) } - - /** Alias for calling [Builder.groupId] with `groupId.orElse(null)`. */ - fun groupId(groupId: Optional) = groupId(groupId.getOrNull()) + fun groupId(): Optional = Optional.ofNullable(groupId.getNullable("group_id")) /** - * Sets [Builder.groupId] to an arbitrary JSON value. + * Permission the ACL grants. Exactly one of `permission` and `role_id` will be provided * - * You should usually call [Builder.groupId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun groupId(groupId: JsonField) = apply { body.groupId(groupId) } - - /** Permission the ACL grants. Exactly one of `permission` and `role_id` will be provided */ - fun permission(permission: Permission?) = apply { body.permission(permission) } - - /** Alias for calling [Builder.permission] with `permission.orElse(null)`. */ - fun permission(permission: Optional) = permission(permission.getOrNull()) + fun permission(): Optional = + Optional.ofNullable(permission.getNullable("permission")) /** - * Sets [Builder.permission] to an arbitrary JSON value. + * When setting a permission directly, optionally restricts the permission grant to just the + * specified object type. Cannot be set alongside a `role_id`. * - * You should usually call [Builder.permission] with a well-typed [Permission] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun permission(permission: JsonField) = apply { body.permission(permission) } + fun restrictObjectType(): Optional = + Optional.ofNullable(restrictObjectType.getNullable("restrict_object_type")) /** - * When setting a permission directly, optionally restricts the permission grant to just the - * specified object type. Cannot be set alongside a `role_id`. + * Id of the role the ACL grants. Exactly one of `permission` and `role_id` will be provided + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun restrictObjectType(restrictObjectType: AclObjectType?) = apply { - body.restrictObjectType(restrictObjectType) - } + fun roleId(): Optional = Optional.ofNullable(roleId.getNullable("role_id")) /** - * Alias for calling [Builder.restrictObjectType] with `restrictObjectType.orElse(null)`. + * Id of the user the ACL applies to. Exactly one of `user_id` and `group_id` will be + * provided + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun restrictObjectType(restrictObjectType: Optional) = - restrictObjectType(restrictObjectType.getOrNull()) + fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) /** - * Sets [Builder.restrictObjectType] to an arbitrary JSON value. + * Returns the raw JSON value of [objectId]. * - * You should usually call [Builder.restrictObjectType] with a well-typed [AclObjectType] - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * Unlike [objectId], this method doesn't throw if the JSON field has an unexpected type. */ - fun restrictObjectType(restrictObjectType: JsonField) = apply { - body.restrictObjectType(restrictObjectType) - } + @JsonProperty("object_id") @ExcludeMissing fun _objectId(): JsonField = objectId /** - * Id of the role the ACL grants. Exactly one of `permission` and `role_id` will be provided + * Returns the raw JSON value of [objectType]. + * + * Unlike [objectType], this method doesn't throw if the JSON field has an unexpected type. */ - fun roleId(roleId: String?) = apply { body.roleId(roleId) } + @JsonProperty("object_type") + @ExcludeMissing + fun _objectType(): JsonField = objectType - /** Alias for calling [Builder.roleId] with `roleId.orElse(null)`. */ - fun roleId(roleId: Optional) = roleId(roleId.getOrNull()) + /** + * Returns the raw JSON value of [groupId]. + * + * Unlike [groupId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("group_id") @ExcludeMissing fun _groupId(): JsonField = groupId /** - * Sets [Builder.roleId] to an arbitrary JSON value. + * Returns the raw JSON value of [permission]. * - * You should usually call [Builder.roleId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [permission], this method doesn't throw if the JSON field has an unexpected type. */ - fun roleId(roleId: JsonField) = apply { body.roleId(roleId) } + @JsonProperty("permission") + @ExcludeMissing + fun _permission(): JsonField = permission /** - * Id of the user the ACL applies to. Exactly one of `user_id` and `group_id` will be - * provided + * Returns the raw JSON value of [restrictObjectType]. + * + * Unlike [restrictObjectType], this method doesn't throw if the JSON field has an + * unexpected type. */ - fun userId(userId: String?) = apply { body.userId(userId) } + @JsonProperty("restrict_object_type") + @ExcludeMissing + fun _restrictObjectType(): JsonField = restrictObjectType - /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ - fun userId(userId: Optional) = userId(userId.getOrNull()) + /** + * Returns the raw JSON value of [roleId]. + * + * Unlike [roleId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("role_id") @ExcludeMissing fun _roleId(): JsonField = roleId /** - * Sets [Builder.userId] to an arbitrary JSON value. + * Returns the raw JSON value of [userId]. * - * You should usually call [Builder.userId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected type. */ - fun userId(userId: JsonField) = apply { body.userId(userId) } + @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .objectId() + * .objectType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var objectId: JsonField? = null + private var objectType: JsonField? = null + private var groupId: JsonField = JsonMissing.of() + private var permission: JsonField = JsonMissing.of() + private var restrictObjectType: JsonField = JsonMissing.of() + private var roleId: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + objectId = body.objectId + objectType = body.objectType + groupId = body.groupId + permission = body.permission + restrictObjectType = body.restrictObjectType + roleId = body.roleId + userId = body.userId + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** The id of the object the ACL applies to */ + fun objectId(objectId: String) = objectId(JsonField.of(objectId)) + + /** + * Sets [Builder.objectId] to an arbitrary JSON value. + * + * You should usually call [Builder.objectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun objectId(objectId: JsonField) = apply { this.objectId = objectId } + + /** The object type that the ACL applies to */ + fun objectType(objectType: AclObjectType) = objectType(JsonField.of(objectType)) - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) + /** + * Sets [Builder.objectType] to an arbitrary JSON value. + * + * You should usually call [Builder.objectType] with a well-typed [AclObjectType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun objectType(objectType: JsonField) = apply { + this.objectType = objectType } - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + /** + * Id of the group the ACL applies to. Exactly one of `user_id` and `group_id` will be + * provided + */ + fun groupId(groupId: String?) = groupId(JsonField.ofNullable(groupId)) - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } + /** Alias for calling [Builder.groupId] with `groupId.orElse(null)`. */ + fun groupId(groupId: Optional) = groupId(groupId.getOrNull()) - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * Sets [Builder.groupId] to an arbitrary JSON value. + * + * You should usually call [Builder.groupId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun groupId(groupId: JsonField) = apply { this.groupId = groupId } - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * Permission the ACL grants. Exactly one of `permission` and `role_id` will be provided + */ + fun permission(permission: Permission?) = permission(JsonField.ofNullable(permission)) - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } + /** Alias for calling [Builder.permission] with `permission.orElse(null)`. */ + fun permission(permission: Optional) = permission(permission.getOrNull()) - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } + /** + * Sets [Builder.permission] to an arbitrary JSON value. + * + * You should usually call [Builder.permission] with a well-typed [Permission] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun permission(permission: JsonField) = apply { + this.permission = permission + } - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** + * When setting a permission directly, optionally restricts the permission grant to just + * the specified object type. Cannot be set alongside a `role_id`. + */ + fun restrictObjectType(restrictObjectType: AclObjectType?) = + restrictObjectType(JsonField.ofNullable(restrictObjectType)) - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** + * Alias for calling [Builder.restrictObjectType] with + * `restrictObjectType.orElse(null)`. + */ + fun restrictObjectType(restrictObjectType: Optional) = + restrictObjectType(restrictObjectType.getOrNull()) - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } + /** + * Sets [Builder.restrictObjectType] to an arbitrary JSON value. + * + * You should usually call [Builder.restrictObjectType] with a well-typed + * [AclObjectType] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun restrictObjectType(restrictObjectType: JsonField) = apply { + this.restrictObjectType = restrictObjectType + } - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } + /** + * Id of the role the ACL grants. Exactly one of `permission` and `role_id` will be + * provided + */ + fun roleId(roleId: String?) = roleId(JsonField.ofNullable(roleId)) - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** Alias for calling [Builder.roleId] with `roleId.orElse(null)`. */ + fun roleId(roleId: Optional) = roleId(roleId.getOrNull()) - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** + * Sets [Builder.roleId] to an arbitrary JSON value. + * + * You should usually call [Builder.roleId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun roleId(roleId: JsonField) = apply { this.roleId = roleId } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + /** + * Id of the user the ACL applies to. Exactly one of `user_id` and `group_id` will be + * provided + */ + fun userId(userId: String?) = userId(JsonField.ofNullable(userId)) - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } + /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ + fun userId(userId: Optional) = userId(userId.getOrNull()) - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + /** + * Sets [Builder.userId] to an arbitrary JSON value. + * + * You should usually call [Builder.userId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun userId(userId: JsonField) = apply { this.userId = userId } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .objectId() + * .objectType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("objectId", objectId), + checkRequired("objectType", objectType), + groupId, + permission, + restrictObjectType, + roleId, + userId, + additionalProperties.toMutableMap(), + ) } - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } + private var validated: Boolean = false - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + fun validate(): Body = apply { + if (validated) { + return@apply + } + + objectId() + objectType() + groupId() + permission() + restrictObjectType() + roleId() + userId() + validated = true } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) + return /* spotless:off */ other is Body && objectId == other.objectId && objectType == other.objectType && groupId == other.groupId && permission == other.permission && restrictObjectType == other.restrictObjectType && roleId == other.roleId && userId == other.userId && additionalProperties == other.additionalProperties /* spotless:on */ } - /** - * Returns an immutable instance of [AclFindAndDeleteParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .objectId() - * .objectType() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): AclFindAndDeleteParams = - AclFindAndDeleteParams( - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(objectId, objectType, groupId, permission, restrictObjectType, roleId, userId, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{objectId=$objectId, objectType=$objectType, groupId=$groupId, permission=$permission, restrictObjectType=$restrictObjectType, roleId=$roleId, userId=$userId, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt index 5804bf46..b4f391b2 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.blocking.AclService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -81,23 +79,30 @@ private constructor( AclListPage(aclsService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -155,7 +160,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt index acd71877..52002368 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.async.AclServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -83,23 +81,30 @@ private constructor( AclListPageAsync(aclsService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -157,7 +162,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListParams.kt index be85a24f..13915530 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListParams.kt @@ -5,7 +5,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.BaseDeserializer import com.braintrustdata.api.core.BaseSerializer import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow @@ -76,31 +75,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = - QueryParams.builder() - .apply { - put("object_id", objectId) - put("object_type", objectType.toString()) - endingBefore?.let { put("ending_before", it) } - ids?.accept( - object : Ids.Visitor { - override fun visitString(string: String) { - put("ids", string) - } - - override fun visitStrings(strings: List) { - put("ids", strings.joinToString(",")) - } - } - ) - limit?.let { put("limit", it.toString()) } - startingAfter?.let { put("starting_after", it) } - putAll(additionalQueryParams) - } - .build() - fun toBuilder() = Builder().from(this) companion object { @@ -118,7 +92,6 @@ private constructor( } /** A builder for [AclListParams]. */ - @NoAutoDetect class Builder internal constructor() { private var objectId: String? = null @@ -325,6 +298,31 @@ private constructor( ) } + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + put("object_id", objectId) + put("object_type", objectType.toString()) + endingBefore?.let { put("ending_before", it) } + ids?.accept( + object : Ids.Visitor { + override fun visitString(string: String) { + put("ids", string) + } + + override fun visitStrings(strings: List) { + put("ids", strings.joinToString(",")) + } + } + ) + limit?.let { put("limit", it.toString()) } + startingAfter?.let { put("starting_after", it) } + putAll(additionalQueryParams) + } + .build() + /** * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclRetrieveParams.kt index 6050054f..ab43fccb 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclRetrieveParams.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers @@ -24,16 +23,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _pathParam(index: Int): String = - when (index) { - 0 -> aclId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - fun toBuilder() = Builder().from(this) companion object { @@ -50,7 +39,6 @@ private constructor( } /** A builder for [AclRetrieveParams]. */ - @NoAutoDetect class Builder internal constructor() { private var aclId: String? = null @@ -185,6 +173,16 @@ private constructor( ) } + fun _pathParam(index: Int): String = + when (index) { + 0 -> aclId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt index 1fbb51db..bb2aafb0 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt @@ -6,18 +6,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -113,35 +111,272 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [AiSecretCreateParams]. + * + * The following fields are required: + * ```java + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AiSecretCreateParams]. */ + class Builder internal constructor() { + + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(aiSecretCreateParams: AiSecretCreateParams) = apply { + body = aiSecretCreateParams.body.toBuilder() + additionalHeaders = aiSecretCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = aiSecretCreateParams.additionalQueryParams.toBuilder() + } + + /** Name of the AI secret */ + fun name(name: String) = apply { body.name(name) } + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { body.name(name) } + + fun metadata(metadata: Metadata?) = apply { body.metadata(metadata) } + + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun metadata(metadata: JsonField) = apply { body.metadata(metadata) } + + /** + * For nearly all users, this parameter should be unnecessary. But in the rare case that + * your API key belongs to multiple organizations, you may specify the name of the + * organization the AI Secret belongs in. + */ + fun orgName(orgName: String?) = apply { body.orgName(orgName) } + + /** Alias for calling [Builder.orgName] with `orgName.orElse(null)`. */ + fun orgName(orgName: Optional) = orgName(orgName.getOrNull()) + + /** + * Sets [Builder.orgName] to an arbitrary JSON value. + * + * You should usually call [Builder.orgName] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun orgName(orgName: JsonField) = apply { body.orgName(orgName) } + + /** + * Secret value. If omitted in a PUT request, the existing secret value will be left intact, + * not replaced with null. + */ + fun secret(secret: String?) = apply { body.secret(secret) } + + /** Alias for calling [Builder.secret] with `secret.orElse(null)`. */ + fun secret(secret: Optional) = secret(secret.getOrNull()) + + /** + * Sets [Builder.secret] to an arbitrary JSON value. + * + * You should usually call [Builder.secret] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun secret(secret: JsonField) = apply { body.secret(secret) } + + fun type(type: String?) = apply { body.type(type) } + + /** Alias for calling [Builder.type] with `type.orElse(null)`. */ + fun type(type: Optional) = type(type.getOrNull()) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun type(type: JsonField) = apply { body.type(type) } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(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 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) + } + + /** + * Returns an immutable instance of [AiSecretCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AiSecretCreateParams = + AiSecretCreateParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + @JvmSynthetic internal fun _body(): Body = body override fun _headers(): Headers = additionalHeaders override fun _queryParams(): QueryParams = additionalQueryParams - @NoAutoDetect class Body - @JsonCreator private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("metadata") - @ExcludeMissing - private val metadata: JsonField = JsonMissing.of(), - @JsonProperty("org_name") - @ExcludeMissing - private val orgName: JsonField = JsonMissing.of(), - @JsonProperty("secret") - @ExcludeMissing - private val secret: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val name: JsonField, + private val metadata: JsonField, + private val orgName: JsonField, + private val secret: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("org_name") @ExcludeMissing orgName: JsonField = JsonMissing.of(), + @JsonProperty("secret") @ExcludeMissing secret: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(name, metadata, orgName, secret, type, mutableMapOf()) + /** * Name of the AI secret * @@ -216,28 +451,19 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - private var validated: Boolean = false + fun toBuilder() = Builder().from(this) - fun validate(): Body = apply { - if (validated) { - return@apply - } - - name() - metadata().ifPresent { it.validate() } - orgName() - secret() - type() - validated = true - } - - fun toBuilder() = Builder().from(this) - - companion object { + companion object { /** * Returns a mutable builder for constructing an instance of [Body]. @@ -385,10 +611,25 @@ private constructor( orgName, secret, type, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + name() + metadata().ifPresent { it.validate() } + orgName() + secret() + type() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -407,267 +648,20 @@ private constructor( "Body{name=$name, metadata=$metadata, orgName=$orgName, secret=$secret, type=$type, additionalProperties=$additionalProperties}" } - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [AiSecretCreateParams]. - * - * The following fields are required: - * ```java - * .name() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [AiSecretCreateParams]. */ - @NoAutoDetect - class Builder internal constructor() { - - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - - @JvmSynthetic - internal fun from(aiSecretCreateParams: AiSecretCreateParams) = apply { - body = aiSecretCreateParams.body.toBuilder() - additionalHeaders = aiSecretCreateParams.additionalHeaders.toBuilder() - additionalQueryParams = aiSecretCreateParams.additionalQueryParams.toBuilder() - } - - /** Name of the AI secret */ - fun name(name: String) = apply { body.name(name) } - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun name(name: JsonField) = apply { body.name(name) } - - fun metadata(metadata: Metadata?) = apply { body.metadata(metadata) } - - /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ - fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) - - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun metadata(metadata: JsonField) = apply { body.metadata(metadata) } - - /** - * For nearly all users, this parameter should be unnecessary. But in the rare case that - * your API key belongs to multiple organizations, you may specify the name of the - * organization the AI Secret belongs in. - */ - fun orgName(orgName: String?) = apply { body.orgName(orgName) } - - /** Alias for calling [Builder.orgName] with `orgName.orElse(null)`. */ - fun orgName(orgName: Optional) = orgName(orgName.getOrNull()) - - /** - * Sets [Builder.orgName] to an arbitrary JSON value. - * - * You should usually call [Builder.orgName] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun orgName(orgName: JsonField) = apply { body.orgName(orgName) } - - /** - * Secret value. If omitted in a PUT request, the existing secret value will be left intact, - * not replaced with null. - */ - fun secret(secret: String?) = apply { body.secret(secret) } - - /** Alias for calling [Builder.secret] with `secret.orElse(null)`. */ - fun secret(secret: Optional) = secret(secret.getOrNull()) - - /** - * Sets [Builder.secret] to an arbitrary JSON value. - * - * You should usually call [Builder.secret] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun secret(secret: JsonField) = apply { body.secret(secret) } - - fun type(type: String?) = apply { body.type(type) } - - /** Alias for calling [Builder.type] with `type.orElse(null)`. */ - fun type(type: Optional) = type(type.getOrNull()) - - /** - * Sets [Builder.type] to an arbitrary JSON value. - * - * You should usually call [Builder.type] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun type(type: JsonField) = apply { body.type(type) } - - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) - } - - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } - - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) - } - - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } - - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } - - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } - - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(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 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) - } + class Metadata + private constructor(private val additionalProperties: MutableMap) { - /** - * Returns an immutable instance of [AiSecretCreateParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): AiSecretCreateParams = - AiSecretCreateParams( - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) - } + @JsonCreator private constructor() : this(mutableMapOf()) - @NoAutoDetect - class Metadata - @JsonCreator - private constructor( @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -711,7 +705,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretDeleteParams.kt index e0f617ff..53f7336b 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretDeleteParams.kt @@ -2,13 +2,15 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.toImmutable +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import java.util.Collections import java.util.Objects import java.util.Optional @@ -18,7 +20,7 @@ private constructor( private val aiSecretId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: Map, + private val additionalBodyProperties: MutableMap, ) : Params { /** AiSecret id */ @@ -28,21 +30,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _additionalBodyProperties(): Map = additionalBodyProperties - - @JvmSynthetic - internal fun _body(): Optional> = - Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - - fun _pathParam(index: Int): String = - when (index) { - 0 -> aiSecretId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders + @JsonAnySetter + private fun putAdditionalBodyProperty(key: String, value: JsonValue) { + additionalBodyProperties.put(key, value) + } - override fun _queryParams(): QueryParams = additionalQueryParams + @JsonAnyGetter + @ExcludeMissing + fun _additionalBodyProperties(): Map = + Collections.unmodifiableMap(additionalBodyProperties) fun toBuilder() = Builder().from(this) @@ -60,7 +56,6 @@ private constructor( } /** A builder for [AiSecretDeleteParams]. */ - @NoAutoDetect class Builder internal constructor() { private var aiSecretId: String? = null @@ -216,10 +211,24 @@ private constructor( checkRequired("aiSecretId", aiSecretId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toImmutable(), + additionalBodyProperties.toMutableMap(), ) } + @JvmSynthetic + internal fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> aiSecretId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParams.kt index 40ba1a94..4ebf4266 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParams.kt @@ -6,18 +6,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -68,187 +66,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("org_name") - @ExcludeMissing - private val orgName: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { - - /** - * Name of the AI secret - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun name(): String = name.getRequired("name") - - /** - * For nearly all users, this parameter should be unnecessary. But in the rare case that - * your API key belongs to multiple organizations, you may specify the name of the - * organization the AI Secret belongs in. - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) - - /** - * Returns the raw JSON value of [name]. - * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - - /** - * Returns the raw JSON value of [orgName]. - * - * Unlike [orgName], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("org_name") @ExcludeMissing fun _orgName(): JsonField = orgName - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } - - name() - orgName() - validated = true - } - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .name() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var name: JsonField? = null - private var orgName: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - name = body.name - orgName = body.orgName - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** Name of the AI secret */ - fun name(name: String) = name(JsonField.of(name)) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } - - /** - * For nearly all users, this parameter should be unnecessary. But in the rare case that - * your API key belongs to multiple organizations, you may specify the name of the - * organization the AI Secret belongs in. - */ - fun orgName(orgName: String?) = orgName(JsonField.ofNullable(orgName)) - - /** Alias for calling [Builder.orgName] with `orgName.orElse(null)`. */ - fun orgName(orgName: Optional) = orgName(orgName.getOrNull()) - - /** - * Sets [Builder.orgName] to an arbitrary JSON value. - * - * You should usually call [Builder.orgName] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun orgName(orgName: JsonField) = apply { this.orgName = orgName } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - 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) - } - - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body(checkRequired("name", name), orgName, additionalProperties.toImmutable()) - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Body && name == other.name && orgName == other.orgName && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, orgName, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Body{name=$name, orgName=$orgName, additionalProperties=$additionalProperties}" - } - fun toBuilder() = Builder().from(this) companion object { @@ -265,7 +82,6 @@ private constructor( } /** A builder for [AiSecretFindAndDeleteParams]. */ - @NoAutoDetect class Builder internal constructor() { private var body: Body.Builder = Body.builder() @@ -445,6 +261,192 @@ private constructor( ) } + @JvmSynthetic internal fun _body(): Body = body + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val name: JsonField, + private val orgName: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("org_name") @ExcludeMissing orgName: JsonField = JsonMissing.of(), + ) : this(name, orgName, mutableMapOf()) + + /** + * Name of the AI secret + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * For nearly all users, this parameter should be unnecessary. But in the rare case that + * your API key belongs to multiple organizations, you may specify the name of the + * organization the AI Secret belongs in. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [orgName]. + * + * Unlike [orgName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("org_name") @ExcludeMissing fun _orgName(): JsonField = orgName + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var name: JsonField? = null + private var orgName: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + name = body.name + orgName = body.orgName + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** Name of the AI secret */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** + * For nearly all users, this parameter should be unnecessary. But in the rare case that + * your API key belongs to multiple organizations, you may specify the name of the + * organization the AI Secret belongs in. + */ + fun orgName(orgName: String?) = orgName(JsonField.ofNullable(orgName)) + + /** Alias for calling [Builder.orgName] with `orgName.orElse(null)`. */ + fun orgName(orgName: Optional) = orgName(orgName.getOrNull()) + + /** + * Sets [Builder.orgName] to an arbitrary JSON value. + * + * You should usually call [Builder.orgName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun orgName(orgName: JsonField) = apply { this.orgName = orgName } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body(checkRequired("name", name), orgName, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + name() + orgName() + validated = true + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && name == other.name && orgName == other.orgName && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(name, orgName, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{name=$name, orgName=$orgName, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt index af920955..67a0e6dc 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.blocking.AiSecretService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -87,23 +85,30 @@ private constructor( AiSecretListPage(aiSecretsService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -161,7 +166,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt index 441b79ce..add111f4 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.async.AiSecretServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -92,23 +90,30 @@ private constructor( ) = AiSecretListPageAsync(aiSecretsService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -168,7 +173,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListParams.kt index 4359719a..ce8926c5 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListParams.kt @@ -5,7 +5,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.BaseDeserializer import com.braintrustdata.api.core.BaseSerializer import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers @@ -78,42 +77,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = - QueryParams.builder() - .apply { - aiSecretName?.let { put("ai_secret_name", it) } - aiSecretType?.accept( - object : AiSecretType.Visitor { - override fun visitString(string: String) { - put("ai_secret_type", string) - } - - override fun visitStrings(strings: List) { - put("ai_secret_type", strings.joinToString(",")) - } - } - ) - endingBefore?.let { put("ending_before", it) } - ids?.accept( - object : Ids.Visitor { - override fun visitString(string: String) { - put("ids", string) - } - - override fun visitStrings(strings: List) { - put("ids", strings.joinToString(",")) - } - } - ) - limit?.let { put("limit", it.toString()) } - orgName?.let { put("org_name", it) } - startingAfter?.let { put("starting_after", it) } - putAll(additionalQueryParams) - } - .build() - fun toBuilder() = Builder().from(this) companion object { @@ -125,7 +88,6 @@ private constructor( } /** A builder for [AiSecretListParams]. */ - @NoAutoDetect class Builder internal constructor() { private var aiSecretName: String? = null @@ -346,6 +308,42 @@ private constructor( ) } + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + aiSecretName?.let { put("ai_secret_name", it) } + aiSecretType?.accept( + object : AiSecretType.Visitor { + override fun visitString(string: String) { + put("ai_secret_type", string) + } + + override fun visitStrings(strings: List) { + put("ai_secret_type", strings.joinToString(",")) + } + } + ) + endingBefore?.let { put("ending_before", it) } + ids?.accept( + object : Ids.Visitor { + override fun visitString(string: String) { + put("ids", string) + } + + override fun visitStrings(strings: List) { + put("ids", strings.joinToString(",")) + } + } + ) + limit?.let { put("limit", it.toString()) } + orgName?.let { put("org_name", it) } + startingAfter?.let { put("starting_after", it) } + putAll(additionalQueryParams) + } + .build() + @JsonDeserialize(using = AiSecretType.Deserializer::class) @JsonSerialize(using = AiSecretType.Serializer::class) class AiSecretType diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt index 9a5a51dd..649fd2a8 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt @@ -6,18 +6,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -113,35 +111,272 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [AiSecretReplaceParams]. + * + * The following fields are required: + * ```java + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AiSecretReplaceParams]. */ + class Builder internal constructor() { + + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(aiSecretReplaceParams: AiSecretReplaceParams) = apply { + body = aiSecretReplaceParams.body.toBuilder() + additionalHeaders = aiSecretReplaceParams.additionalHeaders.toBuilder() + additionalQueryParams = aiSecretReplaceParams.additionalQueryParams.toBuilder() + } + + /** Name of the AI secret */ + fun name(name: String) = apply { body.name(name) } + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { body.name(name) } + + fun metadata(metadata: Metadata?) = apply { body.metadata(metadata) } + + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun metadata(metadata: JsonField) = apply { body.metadata(metadata) } + + /** + * For nearly all users, this parameter should be unnecessary. But in the rare case that + * your API key belongs to multiple organizations, you may specify the name of the + * organization the AI Secret belongs in. + */ + fun orgName(orgName: String?) = apply { body.orgName(orgName) } + + /** Alias for calling [Builder.orgName] with `orgName.orElse(null)`. */ + fun orgName(orgName: Optional) = orgName(orgName.getOrNull()) + + /** + * Sets [Builder.orgName] to an arbitrary JSON value. + * + * You should usually call [Builder.orgName] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun orgName(orgName: JsonField) = apply { body.orgName(orgName) } + + /** + * Secret value. If omitted in a PUT request, the existing secret value will be left intact, + * not replaced with null. + */ + fun secret(secret: String?) = apply { body.secret(secret) } + + /** Alias for calling [Builder.secret] with `secret.orElse(null)`. */ + fun secret(secret: Optional) = secret(secret.getOrNull()) + + /** + * Sets [Builder.secret] to an arbitrary JSON value. + * + * You should usually call [Builder.secret] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun secret(secret: JsonField) = apply { body.secret(secret) } + + fun type(type: String?) = apply { body.type(type) } + + /** Alias for calling [Builder.type] with `type.orElse(null)`. */ + fun type(type: Optional) = type(type.getOrNull()) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun type(type: JsonField) = apply { body.type(type) } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(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 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) + } + + /** + * Returns an immutable instance of [AiSecretReplaceParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AiSecretReplaceParams = + AiSecretReplaceParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + @JvmSynthetic internal fun _body(): Body = body override fun _headers(): Headers = additionalHeaders override fun _queryParams(): QueryParams = additionalQueryParams - @NoAutoDetect class Body - @JsonCreator private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("metadata") - @ExcludeMissing - private val metadata: JsonField = JsonMissing.of(), - @JsonProperty("org_name") - @ExcludeMissing - private val orgName: JsonField = JsonMissing.of(), - @JsonProperty("secret") - @ExcludeMissing - private val secret: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val name: JsonField, + private val metadata: JsonField, + private val orgName: JsonField, + private val secret: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("org_name") @ExcludeMissing orgName: JsonField = JsonMissing.of(), + @JsonProperty("secret") @ExcludeMissing secret: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(name, metadata, orgName, secret, type, mutableMapOf()) + /** * Name of the AI secret * @@ -216,28 +451,19 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - private var validated: Boolean = false + fun toBuilder() = Builder().from(this) - fun validate(): Body = apply { - if (validated) { - return@apply - } - - name() - metadata().ifPresent { it.validate() } - orgName() - secret() - type() - validated = true - } - - fun toBuilder() = Builder().from(this) - - companion object { + companion object { /** * Returns a mutable builder for constructing an instance of [Body]. @@ -385,10 +611,25 @@ private constructor( orgName, secret, type, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + name() + metadata().ifPresent { it.validate() } + orgName() + secret() + type() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -407,267 +648,20 @@ private constructor( "Body{name=$name, metadata=$metadata, orgName=$orgName, secret=$secret, type=$type, additionalProperties=$additionalProperties}" } - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [AiSecretReplaceParams]. - * - * The following fields are required: - * ```java - * .name() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [AiSecretReplaceParams]. */ - @NoAutoDetect - class Builder internal constructor() { - - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - - @JvmSynthetic - internal fun from(aiSecretReplaceParams: AiSecretReplaceParams) = apply { - body = aiSecretReplaceParams.body.toBuilder() - additionalHeaders = aiSecretReplaceParams.additionalHeaders.toBuilder() - additionalQueryParams = aiSecretReplaceParams.additionalQueryParams.toBuilder() - } - - /** Name of the AI secret */ - fun name(name: String) = apply { body.name(name) } - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun name(name: JsonField) = apply { body.name(name) } - - fun metadata(metadata: Metadata?) = apply { body.metadata(metadata) } - - /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ - fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) - - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun metadata(metadata: JsonField) = apply { body.metadata(metadata) } - - /** - * For nearly all users, this parameter should be unnecessary. But in the rare case that - * your API key belongs to multiple organizations, you may specify the name of the - * organization the AI Secret belongs in. - */ - fun orgName(orgName: String?) = apply { body.orgName(orgName) } - - /** Alias for calling [Builder.orgName] with `orgName.orElse(null)`. */ - fun orgName(orgName: Optional) = orgName(orgName.getOrNull()) - - /** - * Sets [Builder.orgName] to an arbitrary JSON value. - * - * You should usually call [Builder.orgName] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun orgName(orgName: JsonField) = apply { body.orgName(orgName) } - - /** - * Secret value. If omitted in a PUT request, the existing secret value will be left intact, - * not replaced with null. - */ - fun secret(secret: String?) = apply { body.secret(secret) } - - /** Alias for calling [Builder.secret] with `secret.orElse(null)`. */ - fun secret(secret: Optional) = secret(secret.getOrNull()) - - /** - * Sets [Builder.secret] to an arbitrary JSON value. - * - * You should usually call [Builder.secret] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun secret(secret: JsonField) = apply { body.secret(secret) } - - fun type(type: String?) = apply { body.type(type) } - - /** Alias for calling [Builder.type] with `type.orElse(null)`. */ - fun type(type: Optional) = type(type.getOrNull()) - - /** - * Sets [Builder.type] to an arbitrary JSON value. - * - * You should usually call [Builder.type] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun type(type: JsonField) = apply { body.type(type) } - - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) - } - - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } - - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) - } - - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } - - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } - - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } - - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(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 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) - } + class Metadata + private constructor(private val additionalProperties: MutableMap) { - /** - * Returns an immutable instance of [AiSecretReplaceParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): AiSecretReplaceParams = - AiSecretReplaceParams( - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) - } + @JsonCreator private constructor() : this(mutableMapOf()) - @NoAutoDetect - class Metadata - @JsonCreator - private constructor( @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -711,7 +705,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretRetrieveParams.kt index c760c49b..551f4d43 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretRetrieveParams.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers @@ -24,16 +23,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _pathParam(index: Int): String = - when (index) { - 0 -> aiSecretId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - fun toBuilder() = Builder().from(this) companion object { @@ -50,7 +39,6 @@ private constructor( } /** A builder for [AiSecretRetrieveParams]. */ - @NoAutoDetect class Builder internal constructor() { private var aiSecretId: String? = null @@ -185,6 +173,16 @@ private constructor( ) } + fun _pathParam(index: Int): String = + when (index) { + 0 -> aiSecretId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt index 93a5ec52..6b47818b 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt @@ -6,18 +6,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -98,239 +96,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - fun _pathParam(index: Int): String = - when (index) { - 0 -> aiSecretId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("metadata") - @ExcludeMissing - private val metadata: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("secret") - @ExcludeMissing - private val secret: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { - - /** - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) - - /** - * Name of the AI secret - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) - - /** - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun secret(): Optional = Optional.ofNullable(secret.getNullable("secret")) - - /** - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun type(): Optional = Optional.ofNullable(type.getNullable("type")) - - /** - * Returns the raw JSON value of [metadata]. - * - * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata - - /** - * Returns the raw JSON value of [name]. - * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - - /** - * Returns the raw JSON value of [secret]. - * - * Unlike [secret], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("secret") @ExcludeMissing fun _secret(): JsonField = secret - - /** - * Returns the raw JSON value of [type]. - * - * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } - - metadata().ifPresent { it.validate() } - name() - secret() - type() - validated = true - } - - fun toBuilder() = Builder().from(this) - - companion object { - - /** Returns a mutable builder for constructing an instance of [Body]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var metadata: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var secret: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - metadata = body.metadata - name = body.name - secret = body.secret - type = body.type - additionalProperties = body.additionalProperties.toMutableMap() - } - - fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) - - /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ - fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) - - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - - /** Name of the AI secret */ - fun name(name: String?) = name(JsonField.ofNullable(name)) - - /** Alias for calling [Builder.name] with `name.orElse(null)`. */ - fun name(name: Optional) = name(name.getOrNull()) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } - - fun secret(secret: String?) = secret(JsonField.ofNullable(secret)) - - /** Alias for calling [Builder.secret] with `secret.orElse(null)`. */ - fun secret(secret: Optional) = secret(secret.getOrNull()) - - /** - * Sets [Builder.secret] to an arbitrary JSON value. - * - * You should usually call [Builder.secret] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun secret(secret: JsonField) = apply { this.secret = secret } - - fun type(type: String?) = type(JsonField.ofNullable(type)) - - /** Alias for calling [Builder.type] with `type.orElse(null)`. */ - fun type(type: Optional) = type(type.getOrNull()) - - /** - * Sets [Builder.type] to an arbitrary JSON value. - * - * You should usually call [Builder.type] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun type(type: JsonField) = apply { this.type = type } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - 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) - } - - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Body = - Body(metadata, name, secret, type, additionalProperties.toImmutable()) - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Body && metadata == other.metadata && name == other.name && secret == other.secret && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(metadata, name, secret, type, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Body{metadata=$metadata, name=$name, secret=$secret, type=$type, additionalProperties=$additionalProperties}" - } - fun toBuilder() = Builder().from(this) companion object { @@ -347,7 +112,6 @@ private constructor( } /** A builder for [AiSecretUpdateParams]. */ - @NoAutoDetect class Builder internal constructor() { private var aiSecretId: String? = null @@ -558,28 +322,259 @@ private constructor( ) } - @NoAutoDetect - class Metadata - @JsonCreator + @JvmSynthetic internal fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> aiSecretId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body private constructor( - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() + private val metadata: JsonField, + private val name: JsonField, + private val secret: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("secret") @ExcludeMissing secret: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(metadata, name, secret, type, mutableMapOf()) + + /** + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + + /** + * Name of the AI secret + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + /** + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun secret(): Optional = Optional.ofNullable(secret.getNullable("secret")) + + /** + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun type(): Optional = Optional.ofNullable(type.getNullable("type")) + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [secret]. + * + * Unlike [secret], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("secret") @ExcludeMissing fun _secret(): JsonField = secret + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Body]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var metadata: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var secret: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + metadata = body.metadata + name = body.name + secret = body.secret + type = body.type + additionalProperties = body.additionalProperties.toMutableMap() + } + + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** Name of the AI secret */ + fun name(name: String?) = name(JsonField.ofNullable(name)) + + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun secret(secret: String?) = secret(JsonField.ofNullable(secret)) + + /** Alias for calling [Builder.secret] with `secret.orElse(null)`. */ + fun secret(secret: Optional) = secret(secret.getOrNull()) + + /** + * Sets [Builder.secret] to an arbitrary JSON value. + * + * You should usually call [Builder.secret] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun secret(secret: JsonField) = apply { this.secret = secret } + + fun type(type: String?) = type(JsonField.ofNullable(type)) + + /** Alias for calling [Builder.type] with `type.orElse(null)`. */ + fun type(type: Optional) = type(type.getOrNull()) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Body = + Body(metadata, name, secret, type, additionalProperties.toMutableMap()) + } private var validated: Boolean = false - fun validate(): Metadata = apply { + fun validate(): Body = apply { if (validated) { return@apply } + metadata().ifPresent { it.validate() } + name() + secret() + type() validated = true } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && metadata == other.metadata && name == other.name && secret == other.secret && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(metadata, name, secret, type, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{metadata=$metadata, name=$name, secret=$secret, type=$type, additionalProperties=$additionalProperties}" + } + + class Metadata + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + fun toBuilder() = Builder().from(this) companion object { @@ -622,7 +617,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKey.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKey.kt index 6cebb35a..1bfec88d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKey.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKey.kt @@ -6,39 +6,43 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class ApiKey -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing private val name: JsonField = JsonMissing.of(), - @JsonProperty("preview_name") - @ExcludeMissing - private val previewName: JsonField = JsonMissing.of(), - @JsonProperty("created") - @ExcludeMissing - private val created: JsonField = JsonMissing.of(), - @JsonProperty("org_id") @ExcludeMissing private val orgId: JsonField = JsonMissing.of(), - @JsonProperty("user_id") - @ExcludeMissing - private val userId: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val name: JsonField, + private val previewName: JsonField, + private val created: JsonField, + private val orgId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("preview_name") + @ExcludeMissing + previewName: JsonField = JsonMissing.of(), + @JsonProperty("created") + @ExcludeMissing + created: JsonField = JsonMissing.of(), + @JsonProperty("org_id") @ExcludeMissing orgId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), + ) : this(id, name, previewName, created, orgId, userId, mutableMapOf()) + /** * Unique identifier for the api key * @@ -129,25 +133,15 @@ private constructor( */ @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): ApiKey = apply { - if (validated) { - return@apply - } - - id() - name() - previewName() - created() - orgId() - userId() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -305,10 +299,26 @@ private constructor( created, orgId, userId, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): ApiKey = apply { + if (validated) { + return@apply + } + + id() + name() + previewName() + created() + orgId() + userId() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyCreateParams.kt index f00eaec8..9c8de109 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyCreateParams.kt @@ -6,18 +6,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -71,187 +69,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("org_name") - @ExcludeMissing - private val orgName: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { - - /** - * Name of the api key. Does not have to be unique - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun name(): String = name.getRequired("name") - - /** - * For nearly all users, this parameter should be unnecessary. But in the rare case that - * your API key belongs to multiple organizations, you may specify the name of the - * organization the API key belongs in. - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) - - /** - * Returns the raw JSON value of [name]. - * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - - /** - * Returns the raw JSON value of [orgName]. - * - * Unlike [orgName], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("org_name") @ExcludeMissing fun _orgName(): JsonField = orgName - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } - - name() - orgName() - validated = true - } - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .name() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var name: JsonField? = null - private var orgName: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - name = body.name - orgName = body.orgName - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** Name of the api key. Does not have to be unique */ - fun name(name: String) = name(JsonField.of(name)) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } - - /** - * For nearly all users, this parameter should be unnecessary. But in the rare case that - * your API key belongs to multiple organizations, you may specify the name of the - * organization the API key belongs in. - */ - fun orgName(orgName: String?) = orgName(JsonField.ofNullable(orgName)) - - /** Alias for calling [Builder.orgName] with `orgName.orElse(null)`. */ - fun orgName(orgName: Optional) = orgName(orgName.getOrNull()) - - /** - * Sets [Builder.orgName] to an arbitrary JSON value. - * - * You should usually call [Builder.orgName] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun orgName(orgName: JsonField) = apply { this.orgName = orgName } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - 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) - } - - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body(checkRequired("name", name), orgName, additionalProperties.toImmutable()) - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Body && name == other.name && orgName == other.orgName && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, orgName, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Body{name=$name, orgName=$orgName, additionalProperties=$additionalProperties}" - } - fun toBuilder() = Builder().from(this) companion object { @@ -268,7 +85,6 @@ private constructor( } /** A builder for [ApiKeyCreateParams]. */ - @NoAutoDetect class Builder internal constructor() { private var body: Body.Builder = Body.builder() @@ -448,6 +264,192 @@ private constructor( ) } + @JvmSynthetic internal fun _body(): Body = body + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val name: JsonField, + private val orgName: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("org_name") @ExcludeMissing orgName: JsonField = JsonMissing.of(), + ) : this(name, orgName, mutableMapOf()) + + /** + * Name of the api key. Does not have to be unique + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * For nearly all users, this parameter should be unnecessary. But in the rare case that + * your API key belongs to multiple organizations, you may specify the name of the + * organization the API key belongs in. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [orgName]. + * + * Unlike [orgName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("org_name") @ExcludeMissing fun _orgName(): JsonField = orgName + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var name: JsonField? = null + private var orgName: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + name = body.name + orgName = body.orgName + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** Name of the api key. Does not have to be unique */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** + * For nearly all users, this parameter should be unnecessary. But in the rare case that + * your API key belongs to multiple organizations, you may specify the name of the + * organization the API key belongs in. + */ + fun orgName(orgName: String?) = orgName(JsonField.ofNullable(orgName)) + + /** Alias for calling [Builder.orgName] with `orgName.orElse(null)`. */ + fun orgName(orgName: Optional) = orgName(orgName.getOrNull()) + + /** + * Sets [Builder.orgName] to an arbitrary JSON value. + * + * You should usually call [Builder.orgName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun orgName(orgName: JsonField) = apply { this.orgName = orgName } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body(checkRequired("name", name), orgName, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + name() + orgName() + validated = true + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && name == other.name && orgName == other.orgName && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(name, orgName, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{name=$name, orgName=$orgName, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParams.kt index 35683e37..ba7d278a 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParams.kt @@ -2,13 +2,15 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.toImmutable +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import java.util.Collections import java.util.Objects import java.util.Optional @@ -18,7 +20,7 @@ private constructor( private val apiKeyId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: Map, + private val additionalBodyProperties: MutableMap, ) : Params { /** ApiKey id */ @@ -28,21 +30,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _additionalBodyProperties(): Map = additionalBodyProperties - - @JvmSynthetic - internal fun _body(): Optional> = - Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - - fun _pathParam(index: Int): String = - when (index) { - 0 -> apiKeyId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders + @JsonAnySetter + private fun putAdditionalBodyProperty(key: String, value: JsonValue) { + additionalBodyProperties.put(key, value) + } - override fun _queryParams(): QueryParams = additionalQueryParams + @JsonAnyGetter + @ExcludeMissing + fun _additionalBodyProperties(): Map = + Collections.unmodifiableMap(additionalBodyProperties) fun toBuilder() = Builder().from(this) @@ -60,7 +56,6 @@ private constructor( } /** A builder for [ApiKeyDeleteParams]. */ - @NoAutoDetect class Builder internal constructor() { private var apiKeyId: String? = null @@ -216,10 +211,24 @@ private constructor( checkRequired("apiKeyId", apiKeyId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toImmutable(), + additionalBodyProperties.toMutableMap(), ) } + @JvmSynthetic + internal fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> apiKeyId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt index 4d1e410a..d5c56dc4 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.blocking.ApiKeyService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -81,23 +79,30 @@ private constructor( ApiKeyListPage(apiKeysService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -155,7 +160,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt index 28dc1058..744c3853 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.async.ApiKeyServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -83,23 +81,30 @@ private constructor( ApiKeyListPageAsync(apiKeysService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -157,7 +162,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListParams.kt index 03c6a458..fa7cd183 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListParams.kt @@ -5,7 +5,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.BaseDeserializer import com.braintrustdata.api.core.BaseSerializer import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers @@ -75,31 +74,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = - QueryParams.builder() - .apply { - apiKeyName?.let { put("api_key_name", it) } - endingBefore?.let { put("ending_before", it) } - ids?.accept( - object : Ids.Visitor { - override fun visitString(string: String) { - put("ids", string) - } - - override fun visitStrings(strings: List) { - put("ids", strings.joinToString(",")) - } - } - ) - limit?.let { put("limit", it.toString()) } - orgName?.let { put("org_name", it) } - startingAfter?.let { put("starting_after", it) } - putAll(additionalQueryParams) - } - .build() - fun toBuilder() = Builder().from(this) companion object { @@ -111,7 +85,6 @@ private constructor( } /** A builder for [ApiKeyListParams]. */ - @NoAutoDetect class Builder internal constructor() { private var apiKeyName: String? = null @@ -316,6 +289,31 @@ private constructor( ) } + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + apiKeyName?.let { put("api_key_name", it) } + endingBefore?.let { put("ending_before", it) } + ids?.accept( + object : Ids.Visitor { + override fun visitString(string: String) { + put("ids", string) + } + + override fun visitStrings(strings: List) { + put("ids", strings.joinToString(",")) + } + } + ) + limit?.let { put("limit", it.toString()) } + orgName?.let { put("org_name", it) } + startingAfter?.let { put("starting_after", it) } + putAll(additionalQueryParams) + } + .build() + /** * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyRetrieveParams.kt index c32d98c6..de3cb891 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyRetrieveParams.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers @@ -24,16 +23,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _pathParam(index: Int): String = - when (index) { - 0 -> apiKeyId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - fun toBuilder() = Builder().from(this) companion object { @@ -50,7 +39,6 @@ private constructor( } /** A builder for [ApiKeyRetrieveParams]. */ - @NoAutoDetect class Builder internal constructor() { private var apiKeyId: String? = null @@ -185,6 +173,16 @@ private constructor( ) } + fun _pathParam(index: Int): String = + when (index) { + 0 -> apiKeyId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImage.kt index 5a3d774a..678e2fee 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImage.kt @@ -7,29 +7,29 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional -@NoAutoDetect class ChatCompletionContentPartImage -@JsonCreator private constructor( - @JsonProperty("image_url") - @ExcludeMissing - private val imageUrl: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing private val type: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val imageUrl: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("image_url") @ExcludeMissing imageUrl: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(imageUrl, type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). @@ -56,21 +56,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): ChatCompletionContentPartImage = apply { - if (validated) { - return@apply - } - - imageUrl().validate() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -161,22 +155,35 @@ private constructor( ChatCompletionContentPartImage( checkRequired("imageUrl", imageUrl), checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } - @NoAutoDetect + private var validated: Boolean = false + + fun validate(): ChatCompletionContentPartImage = apply { + if (validated) { + return@apply + } + + imageUrl().validate() + type() + validated = true + } + class ImageUrl - @JsonCreator private constructor( - @JsonProperty("url") @ExcludeMissing private val url: JsonField = JsonMissing.of(), - @JsonProperty("detail") - @ExcludeMissing - private val detail: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val url: JsonField, + private val detail: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("url") @ExcludeMissing url: JsonField = JsonMissing.of(), + @JsonProperty("detail") @ExcludeMissing detail: JsonField = JsonMissing.of(), + ) : this(url, detail, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). @@ -203,21 +210,15 @@ private constructor( */ @JsonProperty("detail") @ExcludeMissing fun _detail(): JsonField = detail + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): ImageUrl = apply { - if (validated) { - return@apply - } - - url() - detail() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -302,7 +303,19 @@ private constructor( * @throws IllegalStateException if any required field is unset. */ fun build(): ImageUrl = - ImageUrl(checkRequired("url", url), detail, additionalProperties.toImmutable()) + ImageUrl(checkRequired("url", url), detail, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): ImageUrl = apply { + if (validated) { + return@apply + } + + url() + detail() + validated = true } class Detail @JsonCreator private constructor(private val value: JsonField) : Enum { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartText.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartText.kt index 4d14c0cf..e78b84cf 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartText.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartText.kt @@ -7,27 +7,29 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional -@NoAutoDetect class ChatCompletionContentPartText -@JsonCreator private constructor( - @JsonProperty("type") @ExcludeMissing private val type: JsonField = JsonMissing.of(), - @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val type: JsonField, + private val text: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing text: JsonField = JsonMissing.of(), + ) : this(type, text, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). @@ -54,21 +56,15 @@ private constructor( */ @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): ChatCompletionContentPartText = apply { - if (validated) { - return@apply - } - - type() - text() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -155,10 +151,22 @@ private constructor( ChatCompletionContentPartText( checkRequired("type", type), text, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): ChatCompletionContentPartText = apply { + if (validated) { + return@apply + } + + type() + text() + validated = true + } + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { /** diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionMessageToolCall.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionMessageToolCall.kt index 6c3fcd98..c8b11561 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionMessageToolCall.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionMessageToolCall.kt @@ -7,29 +7,30 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects -@NoAutoDetect class ChatCompletionMessageToolCall -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("function") - @ExcludeMissing - private val function: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing private val type: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val function: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("function") @ExcludeMissing function: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(id, function, type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). @@ -69,22 +70,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): ChatCompletionMessageToolCall = apply { - if (validated) { - return@apply - } - - id() - function().validate() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -189,24 +183,38 @@ private constructor( checkRequired("id", id), checkRequired("function", function), checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } - @NoAutoDetect + private var validated: Boolean = false + + fun validate(): ChatCompletionMessageToolCall = apply { + if (validated) { + return@apply + } + + id() + function().validate() + type() + validated = true + } + class Function - @JsonCreator private constructor( - @JsonProperty("arguments") - @ExcludeMissing - private val arguments: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val arguments: JsonField, + private val name: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("arguments") + @ExcludeMissing + arguments: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + ) : this(arguments, name, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). @@ -233,21 +241,15 @@ private constructor( */ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Function = apply { - if (validated) { - return@apply - } - - arguments() - name() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -337,10 +339,22 @@ private constructor( Function( checkRequired("arguments", arguments), checkRequired("name", name), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Function = apply { + if (validated) { + return@apply + } + + arguments() + name() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CodeBundle.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CodeBundle.kt index 56c5f85e..b8f8e53e 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CodeBundle.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CodeBundle.kt @@ -9,11 +9,8 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -26,29 +23,30 @@ import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class CodeBundle -@JsonCreator private constructor( - @JsonProperty("bundle_id") - @ExcludeMissing - private val bundleId: JsonField = JsonMissing.of(), - @JsonProperty("location") - @ExcludeMissing - private val location: JsonField = JsonMissing.of(), - @JsonProperty("runtime_context") - @ExcludeMissing - private val runtimeContext: JsonField = JsonMissing.of(), - @JsonProperty("preview") - @ExcludeMissing - private val preview: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val bundleId: JsonField, + private val location: JsonField, + private val runtimeContext: JsonField, + private val preview: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("bundle_id") @ExcludeMissing bundleId: JsonField = JsonMissing.of(), + @JsonProperty("location") @ExcludeMissing location: JsonField = JsonMissing.of(), + @JsonProperty("runtime_context") + @ExcludeMissing + runtimeContext: JsonField = JsonMissing.of(), + @JsonProperty("preview") @ExcludeMissing preview: JsonField = JsonMissing.of(), + ) : this(bundleId, location, runtimeContext, preview, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). @@ -105,23 +103,15 @@ private constructor( */ @JsonProperty("preview") @ExcludeMissing fun _preview(): JsonField = preview + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): CodeBundle = apply { - if (validated) { - return@apply - } - - bundleId() - location().validate() - runtimeContext().validate() - preview() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -252,10 +242,24 @@ private constructor( checkRequired("location", location), checkRequired("runtimeContext", runtimeContext), preview, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): CodeBundle = apply { + if (validated) { + return@apply + } + + bundleId() + location().validate() + runtimeContext().validate() + preview() + validated = true + } + @JsonDeserialize(using = Location.Deserializer::class) @JsonSerialize(using = Location.Serializer::class) class Location @@ -391,23 +395,25 @@ private constructor( } } - @NoAutoDetect class Experiment - @JsonCreator private constructor( - @JsonProperty("eval_name") - @ExcludeMissing - private val evalName: JsonField = JsonMissing.of(), - @JsonProperty("position") - @ExcludeMissing - private val position: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val evalName: JsonField, + private val position: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("eval_name") + @ExcludeMissing + evalName: JsonField = JsonMissing.of(), + @JsonProperty("position") + @ExcludeMissing + position: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(evalName, position, type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -454,22 +460,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Experiment = apply { - if (validated) { - return@apply - } - - evalName() - position().validate() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -584,10 +583,23 @@ private constructor( checkRequired("evalName", evalName), checkRequired("position", position), checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Experiment = apply { + if (validated) { + return@apply + } + + evalName() + position().validate() + type() + validated = true + } + @JsonDeserialize(using = Position.Deserializer::class) @JsonSerialize(using = Position.Serializer::class) class Position @@ -724,17 +736,19 @@ private constructor( } } - @NoAutoDetect class Type - @JsonCreator private constructor( - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of() + ) : this(type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type or is unexpectedly missing or null (e.g. if the server responded with @@ -750,20 +764,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Type = apply { - if (validated) { - return@apply - } - - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -839,7 +848,18 @@ private constructor( * @throws IllegalStateException if any required field is unset. */ fun build(): Type = - Type(checkRequired("type", type), additionalProperties.toImmutable()) + Type(checkRequired("type", type), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + type() + validated = true } class InnerType @@ -965,20 +985,23 @@ private constructor( "Type{type=$type, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Scorer - @JsonCreator private constructor( - @JsonProperty("index") - @ExcludeMissing - private val index: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val index: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("index") + @ExcludeMissing + index: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + ) : this(index, type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type or is unexpectedly missing or null (e.g. if the server responded with @@ -1009,21 +1032,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Scorer = apply { - if (validated) { - return@apply - } - - index() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1117,10 +1134,22 @@ private constructor( Scorer( checkRequired("index", index), checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Scorer = apply { + if (validated) { + return@apply + } + + index() + type() + validated = true + } + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -1356,20 +1385,19 @@ private constructor( "Experiment{evalName=$evalName, position=$position, type=$type, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Function - @JsonCreator private constructor( - @JsonProperty("index") - @ExcludeMissing - private val index: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val index: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("index") @ExcludeMissing index: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(index, type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -1398,21 +1426,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Function = apply { - if (validated) { - return@apply - } - - index() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1505,10 +1527,22 @@ private constructor( Function( checkRequired("index", index), checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Function = apply { + if (validated) { + return@apply + } + + index() + type() + validated = true + } + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -1625,20 +1659,19 @@ private constructor( } } - @NoAutoDetect class RuntimeContext - @JsonCreator private constructor( - @JsonProperty("runtime") - @ExcludeMissing - private val runtime: JsonField = JsonMissing.of(), - @JsonProperty("version") - @ExcludeMissing - private val version: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val runtime: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("runtime") @ExcludeMissing runtime: JsonField = JsonMissing.of(), + @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), + ) : this(runtime, version, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). @@ -1665,21 +1698,15 @@ private constructor( */ @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): RuntimeContext = apply { - if (validated) { - return@apply - } - - runtime() - version() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1769,10 +1796,22 @@ private constructor( RuntimeContext( checkRequired("runtime", runtime), checkRequired("version", version), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): RuntimeContext = apply { + if (validated) { + return@apply + } + + runtime() + version() + validated = true + } + class Runtime @JsonCreator private constructor(private val value: JsonField) : Enum { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CreateApiKeyOutput.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CreateApiKeyOutput.kt index 24beff8e..4e55702d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CreateApiKeyOutput.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CreateApiKeyOutput.kt @@ -6,40 +6,45 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class CreateApiKeyOutput -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("key") @ExcludeMissing private val key: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing private val name: JsonField = JsonMissing.of(), - @JsonProperty("preview_name") - @ExcludeMissing - private val previewName: JsonField = JsonMissing.of(), - @JsonProperty("created") - @ExcludeMissing - private val created: JsonField = JsonMissing.of(), - @JsonProperty("org_id") @ExcludeMissing private val orgId: JsonField = JsonMissing.of(), - @JsonProperty("user_id") - @ExcludeMissing - private val userId: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val key: JsonField, + private val name: JsonField, + private val previewName: JsonField, + private val created: JsonField, + private val orgId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("key") @ExcludeMissing key: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("preview_name") + @ExcludeMissing + previewName: JsonField = JsonMissing.of(), + @JsonProperty("created") + @ExcludeMissing + created: JsonField = JsonMissing.of(), + @JsonProperty("org_id") @ExcludeMissing orgId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), + ) : this(id, key, name, previewName, created, orgId, userId, mutableMapOf()) + /** * Unique identifier for the api key * @@ -145,26 +150,15 @@ private constructor( */ @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): CreateApiKeyOutput = apply { - if (validated) { - return@apply - } - - id() - key() - name() - previewName() - created() - orgId() - userId() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -338,10 +332,27 @@ private constructor( created, orgId, userId, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): CreateApiKeyOutput = apply { + if (validated) { + return@apply + } + + id() + key() + name() + previewName() + created() + orgId() + userId() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponse.kt index 2b7bead1..2b8708db 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponse.kt @@ -6,34 +6,35 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class CrossObjectInsertResponse -@JsonCreator private constructor( - @JsonProperty("dataset") - @ExcludeMissing - private val dataset: JsonField = JsonMissing.of(), - @JsonProperty("experiment") - @ExcludeMissing - private val experiment: JsonField = JsonMissing.of(), - @JsonProperty("project_logs") - @ExcludeMissing - private val projectLogs: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val dataset: JsonField, + private val experiment: JsonField, + private val projectLogs: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("dataset") @ExcludeMissing dataset: JsonField = JsonMissing.of(), + @JsonProperty("experiment") + @ExcludeMissing + experiment: JsonField = JsonMissing.of(), + @JsonProperty("project_logs") + @ExcludeMissing + projectLogs: JsonField = JsonMissing.of(), + ) : this(dataset, experiment, projectLogs, mutableMapOf()) + /** * A mapping from dataset id to row ids for inserted `events` * @@ -85,22 +86,15 @@ private constructor( @ExcludeMissing fun _projectLogs(): JsonField = projectLogs + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): CrossObjectInsertResponse = apply { - if (validated) { - return@apply - } - - dataset().ifPresent { it.validate() } - experiment().ifPresent { it.validate() } - projectLogs().ifPresent { it.validate() } - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -203,32 +197,38 @@ private constructor( dataset, experiment, projectLogs, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): CrossObjectInsertResponse = apply { + if (validated) { + return@apply + } + + dataset().ifPresent { it.validate() } + experiment().ifPresent { it.validate() } + projectLogs().ifPresent { it.validate() } + validated = true + } + /** A mapping from dataset id to row ids for inserted `events` */ - @NoAutoDetect class Dataset - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Dataset = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -272,7 +272,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Dataset = Dataset(additionalProperties.toImmutable()) + fun build(): Dataset = Dataset(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Dataset = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { @@ -293,27 +303,20 @@ private constructor( } /** A mapping from experiment id to row ids for inserted `events` */ - @NoAutoDetect class Experiment - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Experiment = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -357,7 +360,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Experiment = Experiment(additionalProperties.toImmutable()) + fun build(): Experiment = Experiment(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Experiment = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { @@ -378,27 +391,20 @@ private constructor( } /** A mapping from project id to row ids for inserted `events` */ - @NoAutoDetect class ProjectLogs - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): ProjectLogs = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -442,7 +448,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): ProjectLogs = ProjectLogs(additionalProperties.toImmutable()) + fun build(): ProjectLogs = ProjectLogs(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): ProjectLogs = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DataSummary.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DataSummary.kt index cdcf9fe8..71a1b7ed 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DataSummary.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DataSummary.kt @@ -6,28 +6,29 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects /** Summary of a dataset's data */ -@NoAutoDetect class DataSummary -@JsonCreator private constructor( - @JsonProperty("total_records") - @ExcludeMissing - private val totalRecords: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val totalRecords: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("total_records") + @ExcludeMissing + totalRecords: JsonField = JsonMissing.of() + ) : this(totalRecords, mutableMapOf()) + /** * Total number of records in the dataset * @@ -45,20 +46,15 @@ private constructor( @ExcludeMissing fun _totalRecords(): JsonField = totalRecords + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): DataSummary = apply { - if (validated) { - return@apply - } - - totalRecords() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -133,10 +129,21 @@ private constructor( fun build(): DataSummary = DataSummary( checkRequired("totalRecords", totalRecords), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): DataSummary = apply { + if (validated) { + return@apply + } + + totalRecords() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Dataset.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Dataset.kt index e0a65784..518909cf 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Dataset.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Dataset.kt @@ -6,47 +6,49 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class Dataset -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing private val name: JsonField = JsonMissing.of(), - @JsonProperty("project_id") - @ExcludeMissing - private val projectId: JsonField = JsonMissing.of(), - @JsonProperty("created") - @ExcludeMissing - private val created: JsonField = JsonMissing.of(), - @JsonProperty("deleted_at") - @ExcludeMissing - private val deletedAt: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("metadata") - @ExcludeMissing - private val metadata: JsonField = JsonMissing.of(), - @JsonProperty("user_id") - @ExcludeMissing - private val userId: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val name: JsonField, + private val projectId: JsonField, + private val created: JsonField, + private val deletedAt: JsonField, + private val description: JsonField, + private val metadata: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("project_id") @ExcludeMissing projectId: JsonField = JsonMissing.of(), + @JsonProperty("created") + @ExcludeMissing + created: JsonField = JsonMissing.of(), + @JsonProperty("deleted_at") + @ExcludeMissing + deletedAt: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), + ) : this(id, name, projectId, created, deletedAt, description, metadata, userId, mutableMapOf()) + /** * Unique identifier for the dataset * @@ -171,27 +173,15 @@ private constructor( */ @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Dataset = apply { - if (validated) { - return@apply - } - - id() - name() - projectId() - created() - deletedAt() - description() - metadata().ifPresent { it.validate() } - userId() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -387,32 +377,43 @@ private constructor( description, metadata, userId, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Dataset = apply { + if (validated) { + return@apply + } + + id() + name() + projectId() + created() + deletedAt() + description() + metadata().ifPresent { it.validate() } + userId() + validated = true + } + /** User-controlled metadata about the dataset */ - @NoAutoDetect class Metadata - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -456,7 +457,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt index fb4cd2c4..01d2dbd5 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt @@ -6,18 +6,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -99,263 +97,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("project_id") - @ExcludeMissing - private val projectId: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("metadata") - @ExcludeMissing - private val metadata: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { - - /** - * Name of the dataset. Within a project, dataset names are unique - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun name(): String = name.getRequired("name") - - /** - * Unique identifier for the project that the dataset belongs under - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun projectId(): String = projectId.getRequired("project_id") - - /** - * Textual description of the dataset - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) - - /** - * User-controlled metadata about the dataset - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) - - /** - * Returns the raw JSON value of [name]. - * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - - /** - * Returns the raw JSON value of [projectId]. - * - * Unlike [projectId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("project_id") @ExcludeMissing fun _projectId(): JsonField = projectId - - /** - * Returns the raw JSON value of [description]. - * - * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("description") - @ExcludeMissing - fun _description(): JsonField = description - - /** - * Returns the raw JSON value of [metadata]. - * - * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } - - name() - projectId() - description() - metadata().ifPresent { it.validate() } - validated = true - } - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .name() - * .projectId() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var name: JsonField? = null - private var projectId: JsonField? = null - private var description: JsonField = JsonMissing.of() - private var metadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - name = body.name - projectId = body.projectId - description = body.description - metadata = body.metadata - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** Name of the dataset. Within a project, dataset names are unique */ - fun name(name: String) = name(JsonField.of(name)) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } - - /** Unique identifier for the project that the dataset belongs under */ - fun projectId(projectId: String) = projectId(JsonField.of(projectId)) - - /** - * Sets [Builder.projectId] to an arbitrary JSON value. - * - * You should usually call [Builder.projectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun projectId(projectId: JsonField) = apply { this.projectId = projectId } - - /** Textual description of the dataset */ - fun description(description: String?) = description(JsonField.ofNullable(description)) - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) - - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun description(description: JsonField) = apply { - this.description = description - } - - /** User-controlled metadata about the dataset */ - fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) - - /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ - fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) - - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - 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) - } - - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * .projectId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("name", name), - checkRequired("projectId", projectId), - description, - metadata, - additionalProperties.toImmutable(), - ) - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Body && name == other.name && projectId == other.projectId && description == other.description && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, projectId, description, metadata, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Body{name=$name, projectId=$projectId, description=$description, metadata=$metadata, additionalProperties=$additionalProperties}" - } - fun toBuilder() = Builder().from(this) companion object { @@ -373,7 +114,6 @@ private constructor( } /** A builder for [DatasetCreateParams]. */ - @NoAutoDetect class Builder internal constructor() { private var body: Body.Builder = Body.builder() @@ -578,29 +318,288 @@ private constructor( ) } - /** User-controlled metadata about the dataset */ - @NoAutoDetect - class Metadata - @JsonCreator + @JvmSynthetic internal fun _body(): Body = body + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body private constructor( - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() + private val name: JsonField, + private val projectId: JsonField, + private val description: JsonField, + private val metadata: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this(name, projectId, description, metadata, mutableMapOf()) + + /** + * Name of the dataset. Within a project, dataset names are unique + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * Unique identifier for the project that the dataset belongs under + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun projectId(): String = projectId.getRequired("project_id") + + /** + * Textual description of the dataset + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun description(): Optional = + Optional.ofNullable(description.getNullable("description")) + + /** + * User-controlled metadata about the dataset + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [projectId]. + * + * Unlike [projectId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("project_id") @ExcludeMissing fun _projectId(): JsonField = projectId + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .name() + * .projectId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var name: JsonField? = null + private var projectId: JsonField? = null + private var description: JsonField = JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + name = body.name + projectId = body.projectId + description = body.description + metadata = body.metadata + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** Name of the dataset. Within a project, dataset names are unique */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** Unique identifier for the project that the dataset belongs under */ + fun projectId(projectId: String) = projectId(JsonField.of(projectId)) + + /** + * Sets [Builder.projectId] to an arbitrary JSON value. + * + * You should usually call [Builder.projectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun projectId(projectId: JsonField) = apply { this.projectId = projectId } + + /** Textual description of the dataset */ + fun description(description: String?) = description(JsonField.ofNullable(description)) + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } + + /** User-controlled metadata about the dataset */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * .projectId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("name", name), + checkRequired("projectId", projectId), + description, + metadata, + additionalProperties.toMutableMap(), + ) + } private var validated: Boolean = false - fun validate(): Metadata = apply { + fun validate(): Body = apply { if (validated) { return@apply } + name() + projectId() + description() + metadata().ifPresent { it.validate() } validated = true } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && name == other.name && projectId == other.projectId && description == other.description && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(name, projectId, description, metadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{name=$name, projectId=$projectId, description=$description, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + /** User-controlled metadata about the dataset */ + class Metadata + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + fun toBuilder() = Builder().from(this) companion object { @@ -643,7 +642,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetDeleteParams.kt index 8f10efea..c7a03bab 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetDeleteParams.kt @@ -2,13 +2,15 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.toImmutable +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import java.util.Collections import java.util.Objects import java.util.Optional @@ -18,7 +20,7 @@ private constructor( private val datasetId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: Map, + private val additionalBodyProperties: MutableMap, ) : Params { /** Dataset id */ @@ -28,21 +30,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _additionalBodyProperties(): Map = additionalBodyProperties - - @JvmSynthetic - internal fun _body(): Optional> = - Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - - fun _pathParam(index: Int): String = - when (index) { - 0 -> datasetId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders + @JsonAnySetter + private fun putAdditionalBodyProperty(key: String, value: JsonValue) { + additionalBodyProperties.put(key, value) + } - override fun _queryParams(): QueryParams = additionalQueryParams + @JsonAnyGetter + @ExcludeMissing + fun _additionalBodyProperties(): Map = + Collections.unmodifiableMap(additionalBodyProperties) fun toBuilder() = Builder().from(this) @@ -60,7 +56,6 @@ private constructor( } /** A builder for [DatasetDeleteParams]. */ - @NoAutoDetect class Builder internal constructor() { private var datasetId: String? = null @@ -216,10 +211,24 @@ private constructor( checkRequired("datasetId", datasetId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toImmutable(), + additionalBodyProperties.toMutableMap(), ) } + @JvmSynthetic + internal fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> datasetId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetEvent.kt index 28bf576a..fa1c48ad 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetEvent.kt @@ -6,10 +6,8 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter @@ -17,50 +15,67 @@ import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class DatasetEvent -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("_xact_id") - @ExcludeMissing - private val _xactId: JsonField = JsonMissing.of(), - @JsonProperty("created") - @ExcludeMissing - private val created: JsonField = JsonMissing.of(), - @JsonProperty("dataset_id") - @ExcludeMissing - private val datasetId: JsonField = JsonMissing.of(), - @JsonProperty("project_id") - @ExcludeMissing - private val projectId: JsonField = JsonMissing.of(), - @JsonProperty("root_span_id") - @ExcludeMissing - private val rootSpanId: JsonField = JsonMissing.of(), - @JsonProperty("span_id") - @ExcludeMissing - private val spanId: JsonField = JsonMissing.of(), - @JsonProperty("expected") @ExcludeMissing private val expected: JsonValue = JsonMissing.of(), - @JsonProperty("input") @ExcludeMissing private val input: JsonValue = JsonMissing.of(), - @JsonProperty("is_root") - @ExcludeMissing - private val isRoot: JsonField = JsonMissing.of(), - @JsonProperty("metadata") - @ExcludeMissing - private val metadata: JsonField = JsonMissing.of(), - @JsonProperty("origin") - @ExcludeMissing - private val origin: JsonField = JsonMissing.of(), - @JsonProperty("tags") - @ExcludeMissing - private val tags: JsonField> = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val _xactId: JsonField, + private val created: JsonField, + private val datasetId: JsonField, + private val projectId: JsonField, + private val rootSpanId: JsonField, + private val spanId: JsonField, + private val expected: JsonValue, + private val input: JsonValue, + private val isRoot: JsonField, + private val metadata: JsonField, + private val origin: JsonField, + private val tags: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("_xact_id") @ExcludeMissing _xactId: JsonField = JsonMissing.of(), + @JsonProperty("created") + @ExcludeMissing + created: JsonField = JsonMissing.of(), + @JsonProperty("dataset_id") @ExcludeMissing datasetId: JsonField = JsonMissing.of(), + @JsonProperty("project_id") @ExcludeMissing projectId: JsonField = JsonMissing.of(), + @JsonProperty("root_span_id") + @ExcludeMissing + rootSpanId: JsonField = JsonMissing.of(), + @JsonProperty("span_id") @ExcludeMissing spanId: JsonField = JsonMissing.of(), + @JsonProperty("expected") @ExcludeMissing expected: JsonValue = JsonMissing.of(), + @JsonProperty("input") @ExcludeMissing input: JsonValue = JsonMissing.of(), + @JsonProperty("is_root") @ExcludeMissing isRoot: JsonField = JsonMissing.of(), + @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("origin") + @ExcludeMissing + origin: JsonField = JsonMissing.of(), + @JsonProperty("tags") @ExcludeMissing tags: JsonField> = JsonMissing.of(), + ) : this( + id, + _xactId, + created, + datasetId, + projectId, + rootSpanId, + spanId, + expected, + input, + isRoot, + metadata, + origin, + tags, + mutableMapOf(), + ) + /** * A unique identifier for the dataset event. If you don't provide one, BrainTrust will generate * one for you @@ -244,30 +259,15 @@ private constructor( */ @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): DatasetEvent = apply { - if (validated) { - return@apply - } - - id() - _xactId() - created() - datasetId() - projectId() - rootSpanId() - spanId() - isRoot() - metadata().ifPresent { it.validate() } - origin().ifPresent { it.validate() } - tags() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -564,10 +564,31 @@ private constructor( metadata, origin, (tags ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): DatasetEvent = apply { + if (validated) { + return@apply + } + + id() + _xactId() + created() + datasetId() + projectId() + rootSpanId() + spanId() + isRoot() + metadata().ifPresent { it.validate() } + origin().ifPresent { it.validate() } + tags() + validated = true + } + /** * A dictionary with additional data about the test example, model outputs, or just about * anything else that's relevant, that you can use to help find and analyze examples later. For @@ -575,17 +596,17 @@ private constructor( * slice/dice later. The values in `metadata` can be any JSON-serializable type, but its keys * must be strings */ - @NoAutoDetect class Metadata - @JsonCreator private constructor( - @JsonProperty("model") - @ExcludeMissing - private val model: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val model: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("model") @ExcludeMissing model: JsonField = JsonMissing.of() + ) : this(model, mutableMapOf()) + /** * The model used for this example * @@ -601,20 +622,15 @@ private constructor( */ @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - model() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -675,7 +691,18 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(model, additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(model, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + model() + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFeedbackParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFeedbackParams.kt index fa07b30f..b568875c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFeedbackParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFeedbackParams.kt @@ -6,19 +6,18 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects /** Log feedback for a set of dataset events */ @@ -54,170 +53,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - fun _pathParam(index: Int): String = - when (index) { - 0 -> datasetId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("feedback") - @ExcludeMissing - private val feedback: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { - - /** - * A list of dataset feedback items - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun feedback(): List = feedback.getRequired("feedback") - - /** - * Returns the raw JSON value of [feedback]. - * - * Unlike [feedback], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("feedback") - @ExcludeMissing - fun _feedback(): JsonField> = feedback - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } - - feedback().forEach { it.validate() } - validated = true - } - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .feedback() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var feedback: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - feedback = body.feedback.map { it.toMutableList() } - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** A list of dataset feedback items */ - fun feedback(feedback: List) = feedback(JsonField.of(feedback)) - - /** - * Sets [Builder.feedback] to an arbitrary JSON value. - * - * You should usually call [Builder.feedback] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun feedback(feedback: JsonField>) = apply { - this.feedback = feedback.map { it.toMutableList() } - } - - /** - * Adds a single [FeedbackDatasetItem] to [Builder.feedback]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addFeedback(feedback: FeedbackDatasetItem) = apply { - this.feedback = - (this.feedback ?: JsonField.of(mutableListOf())).also { - checkKnown("feedback", it).add(feedback) - } - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - 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) - } - - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .feedback() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("feedback", feedback).map { it.toImmutable() }, - additionalProperties.toImmutable(), - ) - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Body && feedback == other.feedback && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(feedback, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Body{feedback=$feedback, additionalProperties=$additionalProperties}" - } - fun toBuilder() = Builder().from(this) companion object { @@ -235,7 +70,6 @@ private constructor( } /** A builder for [DatasetFeedbackParams]. */ - @NoAutoDetect class Builder internal constructor() { private var datasetId: String? = null @@ -414,6 +248,178 @@ private constructor( ) } + @JvmSynthetic internal fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> datasetId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val feedback: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("feedback") + @ExcludeMissing + feedback: JsonField> = JsonMissing.of() + ) : this(feedback, mutableMapOf()) + + /** + * A list of dataset feedback items + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun feedback(): List = feedback.getRequired("feedback") + + /** + * Returns the raw JSON value of [feedback]. + * + * Unlike [feedback], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("feedback") + @ExcludeMissing + fun _feedback(): JsonField> = feedback + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .feedback() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var feedback: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + feedback = body.feedback.map { it.toMutableList() } + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** A list of dataset feedback items */ + fun feedback(feedback: List) = feedback(JsonField.of(feedback)) + + /** + * Sets [Builder.feedback] to an arbitrary JSON value. + * + * You should usually call [Builder.feedback] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun feedback(feedback: JsonField>) = apply { + this.feedback = feedback.map { it.toMutableList() } + } + + /** + * Adds a single [FeedbackDatasetItem] to [Builder.feedback]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addFeedback(feedback: FeedbackDatasetItem) = apply { + this.feedback = + (this.feedback ?: JsonField.of(mutableListOf())).also { + checkKnown("feedback", it).add(feedback) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .feedback() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("feedback", feedback).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + feedback().forEach { it.validate() } + validated = true + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && feedback == other.feedback && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(feedback, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{feedback=$feedback, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchParams.kt index ac0671bb..ac9b82f8 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchParams.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers @@ -86,25 +85,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _pathParam(index: Int): String = - when (index) { - 0 -> datasetId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = - QueryParams.builder() - .apply { - limit?.let { put("limit", it.toString()) } - maxRootSpanId?.let { put("max_root_span_id", it) } - maxXactId?.let { put("max_xact_id", it) } - version?.let { put("version", it) } - putAll(additionalQueryParams) - } - .build() - fun toBuilder() = Builder().from(this) companion object { @@ -121,7 +101,6 @@ private constructor( } /** A builder for [DatasetFetchParams]. */ - @NoAutoDetect class Builder internal constructor() { private var datasetId: String? = null @@ -341,6 +320,25 @@ private constructor( ) } + fun _pathParam(index: Int): String = + when (index) { + 0 -> datasetId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + limit?.let { put("limit", it.toString()) } + maxRootSpanId?.let { put("max_root_span_id", it) } + maxXactId?.let { put("max_xact_id", it) } + version?.let { put("version", it) } + putAll(additionalQueryParams) + } + .build() + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt index 96722a3c..6e1d6df2 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt @@ -6,18 +6,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -154,40 +152,39 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body + fun toBuilder() = Builder().from(this) - fun _pathParam(index: Int): String = - when (index) { - 0 -> datasetId - else -> "" - } + companion object { - override fun _headers(): Headers = additionalHeaders + /** + * Returns a mutable builder for constructing an instance of [DatasetFetchPostParams]. + * + * The following fields are required: + * ```java + * .datasetId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun _queryParams(): QueryParams = additionalQueryParams + /** A builder for [DatasetFetchPostParams]. */ + class Builder internal constructor() { - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("cursor") - @ExcludeMissing - private val cursor: JsonField = JsonMissing.of(), - @JsonProperty("limit") - @ExcludeMissing - private val limit: JsonField = JsonMissing.of(), - @JsonProperty("max_root_span_id") - @ExcludeMissing - private val maxRootSpanId: JsonField = JsonMissing.of(), - @JsonProperty("max_xact_id") - @ExcludeMissing - private val maxXactId: JsonField = JsonMissing.of(), - @JsonProperty("version") - @ExcludeMissing - private val version: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + private var datasetId: String? = null + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(datasetFetchPostParams: DatasetFetchPostParams) = apply { + datasetId = datasetFetchPostParams.datasetId + body = datasetFetchPostParams.body.toBuilder() + additionalHeaders = datasetFetchPostParams.additionalHeaders.toBuilder() + additionalQueryParams = datasetFetchPostParams.additionalQueryParams.toBuilder() + } + + /** Dataset id */ + fun datasetId(datasetId: String) = apply { this.datasetId = datasetId } /** * An opaque string to be used as a cursor for the next page of results, in order from @@ -195,11 +192,19 @@ private constructor( * * The string can be obtained directly from the `cursor` property of the previous fetch * query + */ + fun cursor(cursor: String?) = apply { body.cursor(cursor) } + + /** Alias for calling [Builder.cursor] with `cursor.orElse(null)`. */ + fun cursor(cursor: Optional) = cursor(cursor.getOrNull()) + + /** + * Sets [Builder.cursor] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.cursor] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun cursor(): Optional = Optional.ofNullable(cursor.getNullable("cursor")) + fun cursor(cursor: JsonField) = apply { body.cursor(cursor) } /** * limit the number of traces fetched @@ -215,11 +220,26 @@ private constructor( * The `limit` parameter controls the number of full traces to return. So you may end up * with more individual rows than the specified limit if you are fetching events containing * traces. + */ + fun limit(limit: Long?) = apply { body.limit(limit) } + + /** + * Alias for [Builder.limit]. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * This unboxed primitive overload exists for backwards compatibility. */ - fun limit(): Optional = Optional.ofNullable(limit.getNullable("limit")) + fun limit(limit: Long) = limit(limit as Long?) + + /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ + fun limit(limit: Optional) = limit(limit.getOrNull()) + + /** + * Sets [Builder.limit] to an arbitrary JSON value. + * + * You should usually call [Builder.limit] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun limit(limit: JsonField) = apply { body.limit(limit) } /** * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor of @@ -232,12 +252,23 @@ private constructor( * cursor for the next page can be found as the row with the minimum (earliest) value of the * tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an overview of * paginating fetch queries. + */ + fun maxRootSpanId(maxRootSpanId: String?) = apply { body.maxRootSpanId(maxRootSpanId) } + + /** Alias for calling [Builder.maxRootSpanId] with `maxRootSpanId.orElse(null)`. */ + fun maxRootSpanId(maxRootSpanId: Optional) = + maxRootSpanId(maxRootSpanId.getOrNull()) + + /** + * Sets [Builder.maxRootSpanId] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.maxRootSpanId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun maxRootSpanId(): Optional = - Optional.ofNullable(maxRootSpanId.getNullable("max_root_span_id")) + fun maxRootSpanId(maxRootSpanId: JsonField) = apply { + body.maxRootSpanId(maxRootSpanId) + } /** * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor of @@ -250,330 +281,212 @@ private constructor( * cursor for the next page can be found as the row with the minimum (earliest) value of the * tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an overview of * paginating fetch queries. + */ + fun maxXactId(maxXactId: String?) = apply { body.maxXactId(maxXactId) } + + /** Alias for calling [Builder.maxXactId] with `maxXactId.orElse(null)`. */ + fun maxXactId(maxXactId: Optional) = maxXactId(maxXactId.getOrNull()) + + /** + * Sets [Builder.maxXactId] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.maxXactId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun maxXactId(): Optional = - Optional.ofNullable(maxXactId.getNullable("max_xact_id")) + fun maxXactId(maxXactId: JsonField) = apply { body.maxXactId(maxXactId) } /** * Retrieve a snapshot of events from a past time * * The version id is essentially a filter on the latest event transaction id. You can use * the `max_xact_id` returned by a past fetch as the version to reproduce that exact fetch. - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). */ - fun version(): Optional = Optional.ofNullable(version.getNullable("version")) + fun version(version: String?) = apply { body.version(version) } - /** - * Returns the raw JSON value of [cursor]. - * - * Unlike [cursor], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("cursor") @ExcludeMissing fun _cursor(): JsonField = cursor + /** Alias for calling [Builder.version] with `version.orElse(null)`. */ + fun version(version: Optional) = version(version.getOrNull()) /** - * Returns the raw JSON value of [limit]. + * Sets [Builder.version] to an arbitrary JSON value. * - * Unlike [limit], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.version] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("limit") @ExcludeMissing fun _limit(): JsonField = limit + fun version(version: JsonField) = apply { body.version(version) } - /** - * Returns the raw JSON value of [maxRootSpanId]. - * - * Unlike [maxRootSpanId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("max_root_span_id") - @ExcludeMissing - fun _maxRootSpanId(): JsonField = maxRootSpanId + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } - /** - * Returns the raw JSON value of [maxXactId]. - * - * Unlike [maxXactId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("max_xact_id") @ExcludeMissing fun _maxXactId(): JsonField = maxXactId + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } - /** - * Returns the raw JSON value of [version]. - * - * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - private var validated: Boolean = false + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } - fun validate(): Body = apply { - if (validated) { - return@apply - } + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - cursor() - limit() - maxRootSpanId() - maxXactId() - version() - validated = true + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun toBuilder() = Builder().from(this) + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } - companion object { + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - /** Returns a mutable builder for constructing an instance of [Body]. */ - @JvmStatic fun builder() = Builder() + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } - /** A builder for [Body]. */ - class Builder internal constructor() { + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - private var cursor: JsonField = JsonMissing.of() - private var limit: JsonField = JsonMissing.of() - private var maxRootSpanId: JsonField = JsonMissing.of() - private var maxXactId: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - @JvmSynthetic - internal fun from(body: Body) = apply { - cursor = body.cursor - limit = body.limit - maxRootSpanId = body.maxRootSpanId - maxXactId = body.maxXactId - version = body.version - additionalProperties = body.additionalProperties.toMutableMap() - } + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** - * An opaque string to be used as a cursor for the next page of results, in order from - * latest to earliest. - * - * The string can be obtained directly from the `cursor` property of the previous fetch - * query - */ - fun cursor(cursor: String?) = cursor(JsonField.ofNullable(cursor)) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** Alias for calling [Builder.cursor] with `cursor.orElse(null)`. */ - fun cursor(cursor: Optional) = cursor(cursor.getOrNull()) + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Sets [Builder.cursor] to an arbitrary JSON value. - * - * You should usually call [Builder.cursor] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun cursor(cursor: JsonField) = apply { this.cursor = cursor } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } - /** - * limit the number of traces fetched - * - * Fetch queries may be paginated if the total result size is expected to be large (e.g. - * project_logs which accumulate over a long time). Note that fetch queries only support - * pagination in descending time order (from latest to earliest `_xact_id`. Furthermore, - * later pages may return rows which showed up in earlier pages, except with an earlier - * `_xact_id`. This happens because pagination occurs over the whole version history of - * the event log. You will most likely want to exclude any such duplicate, outdated rows - * (by `id`) from your combined result set. - * - * The `limit` parameter controls the number of full traces to return. So you may end up - * with more individual rows than the specified limit if you are fetching events - * containing traces. - */ - fun limit(limit: Long?) = limit(JsonField.ofNullable(limit)) - - /** - * Alias for [Builder.limit]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun limit(limit: Long) = limit(limit as Long?) - - /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ - fun limit(limit: Optional) = limit(limit.getOrNull()) - - /** - * Sets [Builder.limit] to an arbitrary JSON value. - * - * You should usually call [Builder.limit] with a well-typed [Long] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun limit(limit: JsonField) = apply { this.limit = limit } - - /** - * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor - * of the explicit 'cursor' returned by object fetch requests. Please prefer the - * 'cursor' argument going forwards. - * - * Together, `max_xact_id` and `max_root_span_id` form a pagination cursor - * - * Since a paginated fetch query returns results in order from latest to earliest, the - * cursor for the next page can be found as the row with the minimum (earliest) value of - * the tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an - * overview of paginating fetch queries. - */ - fun maxRootSpanId(maxRootSpanId: String?) = - maxRootSpanId(JsonField.ofNullable(maxRootSpanId)) - - /** Alias for calling [Builder.maxRootSpanId] with `maxRootSpanId.orElse(null)`. */ - fun maxRootSpanId(maxRootSpanId: Optional) = - maxRootSpanId(maxRootSpanId.getOrNull()) - - /** - * Sets [Builder.maxRootSpanId] to an arbitrary JSON value. - * - * You should usually call [Builder.maxRootSpanId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun maxRootSpanId(maxRootSpanId: JsonField) = apply { - this.maxRootSpanId = maxRootSpanId - } - - /** - * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor - * of the explicit 'cursor' returned by object fetch requests. Please prefer the - * 'cursor' argument going forwards. - * - * Together, `max_xact_id` and `max_root_span_id` form a pagination cursor - * - * Since a paginated fetch query returns results in order from latest to earliest, the - * cursor for the next page can be found as the row with the minimum (earliest) value of - * the tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an - * overview of paginating fetch queries. - */ - fun maxXactId(maxXactId: String?) = maxXactId(JsonField.ofNullable(maxXactId)) - - /** Alias for calling [Builder.maxXactId] with `maxXactId.orElse(null)`. */ - fun maxXactId(maxXactId: Optional) = maxXactId(maxXactId.getOrNull()) - - /** - * Sets [Builder.maxXactId] to an arbitrary JSON value. - * - * You should usually call [Builder.maxXactId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun maxXactId(maxXactId: JsonField) = apply { this.maxXactId = maxXactId } - - /** - * Retrieve a snapshot of events from a past time - * - * The version id is essentially a filter on the latest event transaction id. You can - * use the `max_xact_id` returned by a past fetch as the version to reproduce that exact - * fetch. - */ - fun version(version: String?) = version(JsonField.ofNullable(version)) - - /** Alias for calling [Builder.version] with `version.orElse(null)`. */ - fun version(version: Optional) = version(version.getOrNull()) - - /** - * Sets [Builder.version] to an arbitrary JSON value. - * - * You should usually call [Builder.version] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun version(version: JsonField) = apply { this.version = version } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Body = - Body( - cursor, - limit, - maxRootSpanId, - maxXactId, - version, - additionalProperties.toImmutable(), - ) + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - return /* spotless:off */ other is Body && cursor == other.cursor && limit == other.limit && maxRootSpanId == other.maxRootSpanId && maxXactId == other.maxXactId && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cursor, limit, maxRootSpanId, maxXactId, version, additionalProperties) } - /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } - override fun hashCode(): Int = hashCode + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - override fun toString() = - "Body{cursor=$cursor, limit=$limit, maxRootSpanId=$maxRootSpanId, maxXactId=$maxXactId, version=$version, additionalProperties=$additionalProperties}" - } + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - fun toBuilder() = Builder().from(this) + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - companion object { + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } /** - * Returns a mutable builder for constructing an instance of [DatasetFetchPostParams]. + * Returns an immutable instance of [DatasetFetchPostParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java * .datasetId() * ``` + * + * @throws IllegalStateException if any required field is unset. */ - @JvmStatic fun builder() = Builder() + fun build(): DatasetFetchPostParams = + DatasetFetchPostParams( + checkRequired("datasetId", datasetId), + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) } - /** A builder for [DatasetFetchPostParams]. */ - @NoAutoDetect - class Builder internal constructor() { - - private var datasetId: String? = null - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + @JvmSynthetic internal fun _body(): Body = body - @JvmSynthetic - internal fun from(datasetFetchPostParams: DatasetFetchPostParams) = apply { - datasetId = datasetFetchPostParams.datasetId - body = datasetFetchPostParams.body.toBuilder() - additionalHeaders = datasetFetchPostParams.additionalHeaders.toBuilder() - additionalQueryParams = datasetFetchPostParams.additionalQueryParams.toBuilder() + fun _pathParam(index: Int): String = + when (index) { + 0 -> datasetId + else -> "" } - /** Dataset id */ - fun datasetId(datasetId: String) = apply { this.datasetId = datasetId } + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val cursor: JsonField, + private val limit: JsonField, + private val maxRootSpanId: JsonField, + private val maxXactId: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cursor") @ExcludeMissing cursor: JsonField = JsonMissing.of(), + @JsonProperty("limit") @ExcludeMissing limit: JsonField = JsonMissing.of(), + @JsonProperty("max_root_span_id") + @ExcludeMissing + maxRootSpanId: JsonField = JsonMissing.of(), + @JsonProperty("max_xact_id") + @ExcludeMissing + maxXactId: JsonField = JsonMissing.of(), + @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), + ) : this(cursor, limit, maxRootSpanId, maxXactId, version, mutableMapOf()) /** * An opaque string to be used as a cursor for the next page of results, in order from @@ -581,19 +494,11 @@ private constructor( * * The string can be obtained directly from the `cursor` property of the previous fetch * query - */ - fun cursor(cursor: String?) = apply { body.cursor(cursor) } - - /** Alias for calling [Builder.cursor] with `cursor.orElse(null)`. */ - fun cursor(cursor: Optional) = cursor(cursor.getOrNull()) - - /** - * Sets [Builder.cursor] to an arbitrary JSON value. * - * You should usually call [Builder.cursor] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun cursor(cursor: JsonField) = apply { body.cursor(cursor) } + fun cursor(): Optional = Optional.ofNullable(cursor.getNullable("cursor")) /** * limit the number of traces fetched @@ -609,26 +514,29 @@ private constructor( * The `limit` parameter controls the number of full traces to return. So you may end up * with more individual rows than the specified limit if you are fetching events containing * traces. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun limit(limit: Long?) = apply { body.limit(limit) } + fun limit(): Optional = Optional.ofNullable(limit.getNullable("limit")) /** - * Alias for [Builder.limit]. + * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor of + * the explicit 'cursor' returned by object fetch requests. Please prefer the 'cursor' + * argument going forwards. * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun limit(limit: Long) = limit(limit as Long?) - - /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ - fun limit(limit: Optional) = limit(limit.getOrNull()) - - /** - * Sets [Builder.limit] to an arbitrary JSON value. + * Together, `max_xact_id` and `max_root_span_id` form a pagination cursor * - * You should usually call [Builder.limit] with a well-typed [Long] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Since a paginated fetch query returns results in order from latest to earliest, the + * cursor for the next page can be found as the row with the minimum (earliest) value of the + * tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an overview of + * paginating fetch queries. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun limit(limit: JsonField) = apply { body.limit(limit) } + fun maxRootSpanId(): Optional = + Optional.ofNullable(maxRootSpanId.getNullable("max_root_span_id")) /** * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor of @@ -641,205 +549,300 @@ private constructor( * cursor for the next page can be found as the row with the minimum (earliest) value of the * tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an overview of * paginating fetch queries. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun maxRootSpanId(maxRootSpanId: String?) = apply { body.maxRootSpanId(maxRootSpanId) } - - /** Alias for calling [Builder.maxRootSpanId] with `maxRootSpanId.orElse(null)`. */ - fun maxRootSpanId(maxRootSpanId: Optional) = - maxRootSpanId(maxRootSpanId.getOrNull()) + fun maxXactId(): Optional = + Optional.ofNullable(maxXactId.getNullable("max_xact_id")) /** - * Sets [Builder.maxRootSpanId] to an arbitrary JSON value. + * Retrieve a snapshot of events from a past time * - * You should usually call [Builder.maxRootSpanId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * The version id is essentially a filter on the latest event transaction id. You can use + * the `max_xact_id` returned by a past fetch as the version to reproduce that exact fetch. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun maxRootSpanId(maxRootSpanId: JsonField) = apply { - body.maxRootSpanId(maxRootSpanId) - } + fun version(): Optional = Optional.ofNullable(version.getNullable("version")) /** - * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor of - * the explicit 'cursor' returned by object fetch requests. Please prefer the 'cursor' - * argument going forwards. - * - * Together, `max_xact_id` and `max_root_span_id` form a pagination cursor + * Returns the raw JSON value of [cursor]. * - * Since a paginated fetch query returns results in order from latest to earliest, the - * cursor for the next page can be found as the row with the minimum (earliest) value of the - * tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an overview of - * paginating fetch queries. + * Unlike [cursor], this method doesn't throw if the JSON field has an unexpected type. */ - fun maxXactId(maxXactId: String?) = apply { body.maxXactId(maxXactId) } - - /** Alias for calling [Builder.maxXactId] with `maxXactId.orElse(null)`. */ - fun maxXactId(maxXactId: Optional) = maxXactId(maxXactId.getOrNull()) + @JsonProperty("cursor") @ExcludeMissing fun _cursor(): JsonField = cursor /** - * Sets [Builder.maxXactId] to an arbitrary JSON value. + * Returns the raw JSON value of [limit]. * - * You should usually call [Builder.maxXactId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [limit], this method doesn't throw if the JSON field has an unexpected type. */ - fun maxXactId(maxXactId: JsonField) = apply { body.maxXactId(maxXactId) } + @JsonProperty("limit") @ExcludeMissing fun _limit(): JsonField = limit /** - * Retrieve a snapshot of events from a past time + * Returns the raw JSON value of [maxRootSpanId]. * - * The version id is essentially a filter on the latest event transaction id. You can use - * the `max_xact_id` returned by a past fetch as the version to reproduce that exact fetch. + * Unlike [maxRootSpanId], this method doesn't throw if the JSON field has an unexpected + * type. */ - fun version(version: String?) = apply { body.version(version) } + @JsonProperty("max_root_span_id") + @ExcludeMissing + fun _maxRootSpanId(): JsonField = maxRootSpanId - /** Alias for calling [Builder.version] with `version.orElse(null)`. */ - fun version(version: Optional) = version(version.getOrNull()) + /** + * Returns the raw JSON value of [maxXactId]. + * + * Unlike [maxXactId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("max_xact_id") @ExcludeMissing fun _maxXactId(): JsonField = maxXactId /** - * Sets [Builder.version] to an arbitrary JSON value. + * Returns the raw JSON value of [version]. * - * You should usually call [Builder.version] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. */ - fun version(version: JsonField) = apply { body.version(version) } + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Body]. */ + @JvmStatic fun builder() = Builder() } - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var cursor: JsonField = JsonMissing.of() + private var limit: JsonField = JsonMissing.of() + private var maxRootSpanId: JsonField = JsonMissing.of() + private var maxXactId: JsonField = JsonMissing.of() + private var version: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + cursor = body.cursor + limit = body.limit + maxRootSpanId = body.maxRootSpanId + maxXactId = body.maxXactId + version = body.version + additionalProperties = body.additionalProperties.toMutableMap() } - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + /** + * An opaque string to be used as a cursor for the next page of results, in order from + * latest to earliest. + * + * The string can be obtained directly from the `cursor` property of the previous fetch + * query + */ + fun cursor(cursor: String?) = cursor(JsonField.ofNullable(cursor)) - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } + /** Alias for calling [Builder.cursor] with `cursor.orElse(null)`. */ + fun cursor(cursor: Optional) = cursor(cursor.getOrNull()) - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * Sets [Builder.cursor] to an arbitrary JSON value. + * + * You should usually call [Builder.cursor] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun cursor(cursor: JsonField) = apply { this.cursor = cursor } - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * limit the number of traces fetched + * + * Fetch queries may be paginated if the total result size is expected to be large (e.g. + * project_logs which accumulate over a long time). Note that fetch queries only support + * pagination in descending time order (from latest to earliest `_xact_id`. Furthermore, + * later pages may return rows which showed up in earlier pages, except with an earlier + * `_xact_id`. This happens because pagination occurs over the whole version history of + * the event log. You will most likely want to exclude any such duplicate, outdated rows + * (by `id`) from your combined result set. + * + * The `limit` parameter controls the number of full traces to return. So you may end up + * with more individual rows than the specified limit if you are fetching events + * containing traces. + */ + fun limit(limit: Long?) = limit(JsonField.ofNullable(limit)) - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } + /** + * Alias for [Builder.limit]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun limit(limit: Long) = limit(limit as Long?) - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } + /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ + fun limit(limit: Optional) = limit(limit.getOrNull()) - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** + * Sets [Builder.limit] to an arbitrary JSON value. + * + * You should usually call [Builder.limit] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun limit(limit: JsonField) = apply { this.limit = limit } - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** + * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor + * of the explicit 'cursor' returned by object fetch requests. Please prefer the + * 'cursor' argument going forwards. + * + * Together, `max_xact_id` and `max_root_span_id` form a pagination cursor + * + * Since a paginated fetch query returns results in order from latest to earliest, the + * cursor for the next page can be found as the row with the minimum (earliest) value of + * the tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an + * overview of paginating fetch queries. + */ + fun maxRootSpanId(maxRootSpanId: String?) = + maxRootSpanId(JsonField.ofNullable(maxRootSpanId)) - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } + /** Alias for calling [Builder.maxRootSpanId] with `maxRootSpanId.orElse(null)`. */ + fun maxRootSpanId(maxRootSpanId: Optional) = + maxRootSpanId(maxRootSpanId.getOrNull()) - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } + /** + * Sets [Builder.maxRootSpanId] to an arbitrary JSON value. + * + * You should usually call [Builder.maxRootSpanId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun maxRootSpanId(maxRootSpanId: JsonField) = apply { + this.maxRootSpanId = maxRootSpanId + } - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** + * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor + * of the explicit 'cursor' returned by object fetch requests. Please prefer the + * 'cursor' argument going forwards. + * + * Together, `max_xact_id` and `max_root_span_id` form a pagination cursor + * + * Since a paginated fetch query returns results in order from latest to earliest, the + * cursor for the next page can be found as the row with the minimum (earliest) value of + * the tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an + * overview of paginating fetch queries. + */ + fun maxXactId(maxXactId: String?) = maxXactId(JsonField.ofNullable(maxXactId)) - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** Alias for calling [Builder.maxXactId] with `maxXactId.orElse(null)`. */ + fun maxXactId(maxXactId: Optional) = maxXactId(maxXactId.getOrNull()) - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + /** + * Sets [Builder.maxXactId] to an arbitrary JSON value. + * + * You should usually call [Builder.maxXactId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun maxXactId(maxXactId: JsonField) = apply { this.maxXactId = maxXactId } - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } + /** + * Retrieve a snapshot of events from a past time + * + * The version id is essentially a filter on the latest event transaction id. You can + * use the `max_xact_id` returned by a past fetch as the version to reproduce that exact + * fetch. + */ + fun version(version: String?) = version(JsonField.ofNullable(version)) - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + /** Alias for calling [Builder.version] with `version.orElse(null)`. */ + fun version(version: Optional) = version(version.getOrNull()) - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + /** + * Sets [Builder.version] to an arbitrary JSON value. + * + * You should usually call [Builder.version] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun version(version: JsonField) = apply { this.version = version } - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Body = + Body( + cursor, + limit, + maxRootSpanId, + maxXactId, + version, + additionalProperties.toMutableMap(), + ) } - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } + private var validated: Boolean = false - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + fun validate(): Body = apply { + if (validated) { + return@apply + } + + cursor() + limit() + maxRootSpanId() + maxXactId() + version() + validated = true } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) + return /* spotless:off */ other is Body && cursor == other.cursor && limit == other.limit && maxRootSpanId == other.maxRootSpanId && maxXactId == other.maxXactId && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ } - /** - * Returns an immutable instance of [DatasetFetchPostParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .datasetId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): DatasetFetchPostParams = - DatasetFetchPostParams( - checkRequired("datasetId", datasetId), - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(cursor, limit, maxRootSpanId, maxXactId, version, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{cursor=$cursor, limit=$limit, maxRootSpanId=$maxRootSpanId, maxXactId=$maxXactId, version=$version, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetInsertParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetInsertParams.kt index 0cc348dd..4310d1a5 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetInsertParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetInsertParams.kt @@ -6,19 +6,18 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects /** Insert a set of events into the dataset */ @@ -54,169 +53,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - fun _pathParam(index: Int): String = - when (index) { - 0 -> datasetId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("events") - @ExcludeMissing - private val events: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { - - /** - * A list of dataset events to insert - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun events(): List = events.getRequired("events") - - /** - * Returns the raw JSON value of [events]. - * - * Unlike [events], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("events") - @ExcludeMissing - fun _events(): JsonField> = events - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } - - events().forEach { it.validate() } - validated = true - } - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .events() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var events: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - events = body.events.map { it.toMutableList() } - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** A list of dataset events to insert */ - fun events(events: List) = events(JsonField.of(events)) - - /** - * Sets [Builder.events] to an arbitrary JSON value. - * - * You should usually call [Builder.events] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun events(events: JsonField>) = apply { - this.events = events.map { it.toMutableList() } - } - - /** - * Adds a single [InsertDatasetEvent] to [events]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addEvent(event: InsertDatasetEvent) = apply { - events = - (events ?: JsonField.of(mutableListOf())).also { - checkKnown("events", it).add(event) - } - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - 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) - } - - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .events() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("events", events).map { it.toImmutable() }, - additionalProperties.toImmutable(), - ) - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Body && events == other.events && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(events, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = "Body{events=$events, additionalProperties=$additionalProperties}" - } - fun toBuilder() = Builder().from(this) companion object { @@ -234,7 +70,6 @@ private constructor( } /** A builder for [DatasetInsertParams]. */ - @NoAutoDetect class Builder internal constructor() { private var datasetId: String? = null @@ -411,6 +246,177 @@ private constructor( ) } + @JvmSynthetic internal fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> datasetId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val events: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("events") + @ExcludeMissing + events: JsonField> = JsonMissing.of() + ) : this(events, mutableMapOf()) + + /** + * A list of dataset events to insert + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun events(): List = events.getRequired("events") + + /** + * Returns the raw JSON value of [events]. + * + * Unlike [events], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("events") + @ExcludeMissing + fun _events(): JsonField> = events + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .events() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var events: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + events = body.events.map { it.toMutableList() } + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** A list of dataset events to insert */ + fun events(events: List) = events(JsonField.of(events)) + + /** + * Sets [Builder.events] to an arbitrary JSON value. + * + * You should usually call [Builder.events] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun events(events: JsonField>) = apply { + this.events = events.map { it.toMutableList() } + } + + /** + * Adds a single [InsertDatasetEvent] to [events]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addEvent(event: InsertDatasetEvent) = apply { + events = + (events ?: JsonField.of(mutableListOf())).also { + checkKnown("events", it).add(event) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .events() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("events", events).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + events().forEach { it.validate() } + validated = true + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && events == other.events && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(events, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = "Body{events=$events, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt index 51260d7d..55ab6c83 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.blocking.DatasetService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -87,23 +85,30 @@ private constructor( DatasetListPage(datasetsService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -161,7 +166,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt index 7e0a0e47..58f04b63 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.async.DatasetServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -92,23 +90,30 @@ private constructor( ) = DatasetListPageAsync(datasetsService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -166,7 +171,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListParams.kt index 90416929..d0f311fc 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListParams.kt @@ -5,7 +5,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.BaseDeserializer import com.braintrustdata.api.core.BaseSerializer import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers @@ -83,33 +82,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = - QueryParams.builder() - .apply { - datasetName?.let { put("dataset_name", it) } - endingBefore?.let { put("ending_before", it) } - ids?.accept( - object : Ids.Visitor { - override fun visitString(string: String) { - put("ids", string) - } - - override fun visitStrings(strings: List) { - put("ids", strings.joinToString(",")) - } - } - ) - limit?.let { put("limit", it.toString()) } - orgName?.let { put("org_name", it) } - projectId?.let { put("project_id", it) } - projectName?.let { put("project_name", it) } - startingAfter?.let { put("starting_after", it) } - putAll(additionalQueryParams) - } - .build() - fun toBuilder() = Builder().from(this) companion object { @@ -121,7 +93,6 @@ private constructor( } /** A builder for [DatasetListParams]. */ - @NoAutoDetect class Builder internal constructor() { private var datasetName: String? = null @@ -344,6 +315,33 @@ private constructor( ) } + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + datasetName?.let { put("dataset_name", it) } + endingBefore?.let { put("ending_before", it) } + ids?.accept( + object : Ids.Visitor { + override fun visitString(string: String) { + put("ids", string) + } + + override fun visitStrings(strings: List) { + put("ids", strings.joinToString(",")) + } + } + ) + limit?.let { put("limit", it.toString()) } + orgName?.let { put("org_name", it) } + projectId?.let { put("project_id", it) } + projectName?.let { put("project_name", it) } + startingAfter?.let { put("starting_after", it) } + putAll(additionalQueryParams) + } + .build() + /** * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetRetrieveParams.kt index 57c19cd2..27bc2e38 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetRetrieveParams.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers @@ -24,16 +23,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _pathParam(index: Int): String = - when (index) { - 0 -> datasetId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - fun toBuilder() = Builder().from(this) companion object { @@ -50,7 +39,6 @@ private constructor( } /** A builder for [DatasetRetrieveParams]. */ - @NoAutoDetect class Builder internal constructor() { private var datasetId: String? = null @@ -185,6 +173,16 @@ private constructor( ) } + fun _pathParam(index: Int): String = + when (index) { + 0 -> datasetId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetSummarizeParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetSummarizeParams.kt index f20aadaf..998d598b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetSummarizeParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetSummarizeParams.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers @@ -30,22 +29,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _pathParam(index: Int): String = - when (index) { - 0 -> datasetId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = - QueryParams.builder() - .apply { - summarizeData?.let { put("summarize_data", it.toString()) } - putAll(additionalQueryParams) - } - .build() - fun toBuilder() = Builder().from(this) companion object { @@ -62,7 +45,6 @@ private constructor( } /** A builder for [DatasetSummarizeParams]. */ - @NoAutoDetect class Builder internal constructor() { private var datasetId: String? = null @@ -216,6 +198,22 @@ private constructor( ) } + fun _pathParam(index: Int): String = + when (index) { + 0 -> datasetId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + summarizeData?.let { put("summarize_data", it.toString()) } + putAll(additionalQueryParams) + } + .build() + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt index 8f6201b2..c605eabf 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt @@ -6,18 +6,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -89,217 +87,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - fun _pathParam(index: Int): String = - when (index) { - 0 -> datasetId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("metadata") - @ExcludeMissing - private val metadata: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { - - /** - * Textual description of the dataset - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) - - /** - * User-controlled metadata about the dataset - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) - - /** - * Name of the dataset. Within a project, dataset names are unique - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) - - /** - * Returns the raw JSON value of [description]. - * - * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("description") - @ExcludeMissing - fun _description(): JsonField = description - - /** - * Returns the raw JSON value of [metadata]. - * - * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata - - /** - * Returns the raw JSON value of [name]. - * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } - - description() - metadata().ifPresent { it.validate() } - name() - validated = true - } - - fun toBuilder() = Builder().from(this) - - companion object { - - /** Returns a mutable builder for constructing an instance of [Body]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var description: JsonField = JsonMissing.of() - private var metadata: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - description = body.description - metadata = body.metadata - name = body.name - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** Textual description of the dataset */ - fun description(description: String?) = description(JsonField.ofNullable(description)) - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) - - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun description(description: JsonField) = apply { - this.description = description - } - - /** User-controlled metadata about the dataset */ - fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) - - /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ - fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) - - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - - /** Name of the dataset. Within a project, dataset names are unique */ - fun name(name: String?) = name(JsonField.ofNullable(name)) - - /** Alias for calling [Builder.name] with `name.orElse(null)`. */ - fun name(name: Optional) = name(name.getOrNull()) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - 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) - } - - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Body = - Body(description, metadata, name, additionalProperties.toImmutable()) - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Body && description == other.description && metadata == other.metadata && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(description, metadata, name, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Body{description=$description, metadata=$metadata, name=$name, additionalProperties=$additionalProperties}" - } - fun toBuilder() = Builder().from(this) companion object { @@ -316,7 +103,6 @@ private constructor( } /** A builder for [DatasetUpdateParams]. */ - @NoAutoDetect class Builder internal constructor() { private var datasetId: String? = null @@ -517,29 +303,241 @@ private constructor( ) } - /** User-controlled metadata about the dataset */ - @NoAutoDetect - class Metadata - @JsonCreator + @JvmSynthetic internal fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> datasetId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body private constructor( - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() + private val description: JsonField, + private val metadata: JsonField, + private val name: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + ) : this(description, metadata, name, mutableMapOf()) + + /** + * Textual description of the dataset + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun description(): Optional = + Optional.ofNullable(description.getNullable("description")) + + /** + * User-controlled metadata about the dataset + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + + /** + * Name of the dataset. Within a project, dataset names are unique + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Body]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var description: JsonField = JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + description = body.description + metadata = body.metadata + name = body.name + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** Textual description of the dataset */ + fun description(description: String?) = description(JsonField.ofNullable(description)) + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } + + /** User-controlled metadata about the dataset */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** Name of the dataset. Within a project, dataset names are unique */ + fun name(name: String?) = name(JsonField.ofNullable(name)) + + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Body = + Body(description, metadata, name, additionalProperties.toMutableMap()) + } private var validated: Boolean = false - fun validate(): Metadata = apply { + fun validate(): Body = apply { if (validated) { return@apply } + description() + metadata().ifPresent { it.validate() } + name() validated = true } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && description == other.description && metadata == other.metadata && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(description, metadata, name, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{description=$description, metadata=$metadata, name=$name, additionalProperties=$additionalProperties}" + } + + /** User-controlled metadata about the dataset */ + class Metadata + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + fun toBuilder() = Builder().from(this) companion object { @@ -582,7 +580,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVar.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVar.kt index 739d7149..1369d011 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVar.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVar.kt @@ -7,41 +7,43 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class EnvVar -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing private val name: JsonField = JsonMissing.of(), - @JsonProperty("object_id") - @ExcludeMissing - private val objectId: JsonField = JsonMissing.of(), - @JsonProperty("object_type") - @ExcludeMissing - private val objectType: JsonField = JsonMissing.of(), - @JsonProperty("created") - @ExcludeMissing - private val created: JsonField = JsonMissing.of(), - @JsonProperty("used") - @ExcludeMissing - private val used: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val name: JsonField, + private val objectId: JsonField, + private val objectType: JsonField, + private val created: JsonField, + private val used: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("object_id") @ExcludeMissing objectId: JsonField = JsonMissing.of(), + @JsonProperty("object_type") + @ExcludeMissing + objectType: JsonField = JsonMissing.of(), + @JsonProperty("created") + @ExcludeMissing + created: JsonField = JsonMissing.of(), + @JsonProperty("used") @ExcludeMissing used: JsonField = JsonMissing.of(), + ) : this(id, name, objectId, objectType, created, used, mutableMapOf()) + /** * Unique identifier for the environment variable * @@ -134,25 +136,15 @@ private constructor( */ @JsonProperty("used") @ExcludeMissing fun _used(): JsonField = used + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): EnvVar = apply { - if (validated) { - return@apply - } - - id() - name() - objectId() - objectType() - created() - used() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -311,10 +303,26 @@ private constructor( checkRequired("objectType", objectType), created, used, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): EnvVar = apply { + if (validated) { + return@apply + } + + id() + name() + objectId() + objectType() + created() + used() + validated = true + } + /** The type of the object the environment variable is scoped for */ class ObjectType @JsonCreator private constructor(private val value: JsonField) : Enum { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarCreateParams.kt index ba236659..6a61e390 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarCreateParams.kt @@ -7,18 +7,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -100,32 +98,251 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [EnvVarCreateParams]. + * + * The following fields are required: + * ```java + * .name() + * .objectId() + * .objectType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [EnvVarCreateParams]. */ + class Builder internal constructor() { + + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(envVarCreateParams: EnvVarCreateParams) = apply { + body = envVarCreateParams.body.toBuilder() + additionalHeaders = envVarCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = envVarCreateParams.additionalQueryParams.toBuilder() + } + + /** The name of the environment variable */ + fun name(name: String) = apply { body.name(name) } + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { body.name(name) } + + /** The id of the object the environment variable is scoped for */ + fun objectId(objectId: String) = apply { body.objectId(objectId) } + + /** + * Sets [Builder.objectId] to an arbitrary JSON value. + * + * You should usually call [Builder.objectId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun objectId(objectId: JsonField) = apply { body.objectId(objectId) } + + /** The type of the object the environment variable is scoped for */ + fun objectType(objectType: ObjectType) = apply { body.objectType(objectType) } + + /** + * Sets [Builder.objectType] to an arbitrary JSON value. + * + * You should usually call [Builder.objectType] with a well-typed [ObjectType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun objectType(objectType: JsonField) = apply { body.objectType(objectType) } + + /** The value of the environment variable. Will be encrypted at rest. */ + fun value(value: String?) = apply { body.value(value) } + + /** Alias for calling [Builder.value] with `value.orElse(null)`. */ + fun value(value: Optional) = value(value.getOrNull()) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun value(value: JsonField) = apply { body.value(value) } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(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 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) + } + + /** + * Returns an immutable instance of [EnvVarCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * .objectId() + * .objectType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EnvVarCreateParams = + EnvVarCreateParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + @JvmSynthetic internal fun _body(): Body = body override fun _headers(): Headers = additionalHeaders override fun _queryParams(): QueryParams = additionalQueryParams - @NoAutoDetect class Body - @JsonCreator private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("object_id") - @ExcludeMissing - private val objectId: JsonField = JsonMissing.of(), - @JsonProperty("object_type") - @ExcludeMissing - private val objectType: JsonField = JsonMissing.of(), - @JsonProperty("value") - @ExcludeMissing - private val value: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val name: JsonField, + private val objectId: JsonField, + private val objectType: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("object_id") + @ExcludeMissing + objectId: JsonField = JsonMissing.of(), + @JsonProperty("object_type") + @ExcludeMissing + objectType: JsonField = JsonMissing.of(), + @JsonProperty("value") @ExcludeMissing value: JsonField = JsonMissing.of(), + ) : this(name, objectId, objectType, value, mutableMapOf()) + /** * The name of the environment variable * @@ -188,23 +405,15 @@ private constructor( */ @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } - - name() - objectId() - objectType() - value() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -333,10 +542,24 @@ private constructor( checkRequired("objectId", objectId), checkRequired("objectType", objectType), value, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + name() + objectId() + objectType() + value() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -355,225 +578,6 @@ private constructor( "Body{name=$name, objectId=$objectId, objectType=$objectType, value=$value, additionalProperties=$additionalProperties}" } - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [EnvVarCreateParams]. - * - * The following fields are required: - * ```java - * .name() - * .objectId() - * .objectType() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [EnvVarCreateParams]. */ - @NoAutoDetect - class Builder internal constructor() { - - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - - @JvmSynthetic - internal fun from(envVarCreateParams: EnvVarCreateParams) = apply { - body = envVarCreateParams.body.toBuilder() - additionalHeaders = envVarCreateParams.additionalHeaders.toBuilder() - additionalQueryParams = envVarCreateParams.additionalQueryParams.toBuilder() - } - - /** The name of the environment variable */ - fun name(name: String) = apply { body.name(name) } - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun name(name: JsonField) = apply { body.name(name) } - - /** The id of the object the environment variable is scoped for */ - fun objectId(objectId: String) = apply { body.objectId(objectId) } - - /** - * Sets [Builder.objectId] to an arbitrary JSON value. - * - * You should usually call [Builder.objectId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun objectId(objectId: JsonField) = apply { body.objectId(objectId) } - - /** The type of the object the environment variable is scoped for */ - fun objectType(objectType: ObjectType) = apply { body.objectType(objectType) } - - /** - * Sets [Builder.objectType] to an arbitrary JSON value. - * - * You should usually call [Builder.objectType] with a well-typed [ObjectType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun objectType(objectType: JsonField) = apply { body.objectType(objectType) } - - /** The value of the environment variable. Will be encrypted at rest. */ - fun value(value: String?) = apply { body.value(value) } - - /** Alias for calling [Builder.value] with `value.orElse(null)`. */ - fun value(value: Optional) = value(value.getOrNull()) - - /** - * Sets [Builder.value] to an arbitrary JSON value. - * - * You should usually call [Builder.value] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun value(value: JsonField) = apply { body.value(value) } - - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) - } - - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } - - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) - } - - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } - - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } - - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } - - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(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 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) - } - - /** - * Returns an immutable instance of [EnvVarCreateParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * .objectId() - * .objectType() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): EnvVarCreateParams = - EnvVarCreateParams( - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) - } - /** The type of the object the environment variable is scoped for */ class ObjectType @JsonCreator private constructor(private val value: JsonField) : Enum { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarDeleteParams.kt index ba7bb844..2db92a78 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarDeleteParams.kt @@ -2,13 +2,15 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.toImmutable +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import java.util.Collections import java.util.Objects import java.util.Optional @@ -18,7 +20,7 @@ private constructor( private val envVarId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: Map, + private val additionalBodyProperties: MutableMap, ) : Params { /** EnvVar id */ @@ -28,21 +30,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _additionalBodyProperties(): Map = additionalBodyProperties - - @JvmSynthetic - internal fun _body(): Optional> = - Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - - fun _pathParam(index: Int): String = - when (index) { - 0 -> envVarId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders + @JsonAnySetter + private fun putAdditionalBodyProperty(key: String, value: JsonValue) { + additionalBodyProperties.put(key, value) + } - override fun _queryParams(): QueryParams = additionalQueryParams + @JsonAnyGetter + @ExcludeMissing + fun _additionalBodyProperties(): Map = + Collections.unmodifiableMap(additionalBodyProperties) fun toBuilder() = Builder().from(this) @@ -60,7 +56,6 @@ private constructor( } /** A builder for [EnvVarDeleteParams]. */ - @NoAutoDetect class Builder internal constructor() { private var envVarId: String? = null @@ -216,10 +211,24 @@ private constructor( checkRequired("envVarId", envVarId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toImmutable(), + additionalBodyProperties.toMutableMap(), ) } + @JvmSynthetic + internal fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> envVarId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListParams.kt index b4633176..a23dfdfe 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListParams.kt @@ -5,7 +5,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.BaseDeserializer import com.braintrustdata.api.core.BaseSerializer import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers @@ -59,30 +58,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = - QueryParams.builder() - .apply { - envVarName?.let { put("env_var_name", it) } - ids?.accept( - object : Ids.Visitor { - override fun visitString(string: String) { - put("ids", string) - } - - override fun visitStrings(strings: List) { - put("ids", strings.joinToString(",")) - } - } - ) - limit?.let { put("limit", it.toString()) } - objectId?.let { put("object_id", it) } - objectType?.let { put("object_type", it.toString()) } - putAll(additionalQueryParams) - } - .build() - fun toBuilder() = Builder().from(this) companion object { @@ -94,7 +69,6 @@ private constructor( } /** A builder for [EnvVarListParams]. */ - @NoAutoDetect class Builder internal constructor() { private var envVarName: String? = null @@ -277,6 +251,30 @@ private constructor( ) } + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + envVarName?.let { put("env_var_name", it) } + ids?.accept( + object : Ids.Visitor { + override fun visitString(string: String) { + put("ids", string) + } + + override fun visitStrings(strings: List) { + put("ids", strings.joinToString(",")) + } + } + ) + limit?.let { put("limit", it.toString()) } + objectId?.let { put("object_id", it) } + objectType?.let { put("object_type", it.toString()) } + putAll(additionalQueryParams) + } + .build() + /** * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListResponse.kt index dc10c986..4711a9ad 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListResponse.kt @@ -6,28 +6,28 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects -@NoAutoDetect class EnvVarListResponse -@JsonCreator private constructor( - @JsonProperty("objects") - @ExcludeMissing - private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") @ExcludeMissing objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + /** * A list of env_var objects * @@ -43,20 +43,15 @@ private constructor( */ @JsonProperty("objects") @ExcludeMissing fun _objects(): JsonField> = objects + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): EnvVarListResponse = apply { - if (validated) { - return@apply - } - - objects().forEach { it.validate() } - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -145,10 +140,21 @@ private constructor( fun build(): EnvVarListResponse = EnvVarListResponse( checkRequired("objects", objects).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): EnvVarListResponse = apply { + if (validated) { + return@apply + } + + objects().forEach { it.validate() } + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarReplaceParams.kt index 4c9da803..9935a350 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarReplaceParams.kt @@ -7,18 +7,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -100,32 +98,251 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [EnvVarReplaceParams]. + * + * The following fields are required: + * ```java + * .name() + * .objectId() + * .objectType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [EnvVarReplaceParams]. */ + class Builder internal constructor() { + + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(envVarReplaceParams: EnvVarReplaceParams) = apply { + body = envVarReplaceParams.body.toBuilder() + additionalHeaders = envVarReplaceParams.additionalHeaders.toBuilder() + additionalQueryParams = envVarReplaceParams.additionalQueryParams.toBuilder() + } + + /** The name of the environment variable */ + fun name(name: String) = apply { body.name(name) } + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { body.name(name) } + + /** The id of the object the environment variable is scoped for */ + fun objectId(objectId: String) = apply { body.objectId(objectId) } + + /** + * Sets [Builder.objectId] to an arbitrary JSON value. + * + * You should usually call [Builder.objectId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun objectId(objectId: JsonField) = apply { body.objectId(objectId) } + + /** The type of the object the environment variable is scoped for */ + fun objectType(objectType: ObjectType) = apply { body.objectType(objectType) } + + /** + * Sets [Builder.objectType] to an arbitrary JSON value. + * + * You should usually call [Builder.objectType] with a well-typed [ObjectType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun objectType(objectType: JsonField) = apply { body.objectType(objectType) } + + /** The value of the environment variable. Will be encrypted at rest. */ + fun value(value: String?) = apply { body.value(value) } + + /** Alias for calling [Builder.value] with `value.orElse(null)`. */ + fun value(value: Optional) = value(value.getOrNull()) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun value(value: JsonField) = apply { body.value(value) } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(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 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) + } + + /** + * Returns an immutable instance of [EnvVarReplaceParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * .objectId() + * .objectType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EnvVarReplaceParams = + EnvVarReplaceParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + @JvmSynthetic internal fun _body(): Body = body override fun _headers(): Headers = additionalHeaders override fun _queryParams(): QueryParams = additionalQueryParams - @NoAutoDetect class Body - @JsonCreator private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("object_id") - @ExcludeMissing - private val objectId: JsonField = JsonMissing.of(), - @JsonProperty("object_type") - @ExcludeMissing - private val objectType: JsonField = JsonMissing.of(), - @JsonProperty("value") - @ExcludeMissing - private val value: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val name: JsonField, + private val objectId: JsonField, + private val objectType: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("object_id") + @ExcludeMissing + objectId: JsonField = JsonMissing.of(), + @JsonProperty("object_type") + @ExcludeMissing + objectType: JsonField = JsonMissing.of(), + @JsonProperty("value") @ExcludeMissing value: JsonField = JsonMissing.of(), + ) : this(name, objectId, objectType, value, mutableMapOf()) + /** * The name of the environment variable * @@ -188,23 +405,15 @@ private constructor( */ @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } - - name() - objectId() - objectType() - value() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -333,10 +542,24 @@ private constructor( checkRequired("objectId", objectId), checkRequired("objectType", objectType), value, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + name() + objectId() + objectType() + value() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -355,225 +578,6 @@ private constructor( "Body{name=$name, objectId=$objectId, objectType=$objectType, value=$value, additionalProperties=$additionalProperties}" } - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [EnvVarReplaceParams]. - * - * The following fields are required: - * ```java - * .name() - * .objectId() - * .objectType() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [EnvVarReplaceParams]. */ - @NoAutoDetect - class Builder internal constructor() { - - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - - @JvmSynthetic - internal fun from(envVarReplaceParams: EnvVarReplaceParams) = apply { - body = envVarReplaceParams.body.toBuilder() - additionalHeaders = envVarReplaceParams.additionalHeaders.toBuilder() - additionalQueryParams = envVarReplaceParams.additionalQueryParams.toBuilder() - } - - /** The name of the environment variable */ - fun name(name: String) = apply { body.name(name) } - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun name(name: JsonField) = apply { body.name(name) } - - /** The id of the object the environment variable is scoped for */ - fun objectId(objectId: String) = apply { body.objectId(objectId) } - - /** - * Sets [Builder.objectId] to an arbitrary JSON value. - * - * You should usually call [Builder.objectId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun objectId(objectId: JsonField) = apply { body.objectId(objectId) } - - /** The type of the object the environment variable is scoped for */ - fun objectType(objectType: ObjectType) = apply { body.objectType(objectType) } - - /** - * Sets [Builder.objectType] to an arbitrary JSON value. - * - * You should usually call [Builder.objectType] with a well-typed [ObjectType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun objectType(objectType: JsonField) = apply { body.objectType(objectType) } - - /** The value of the environment variable. Will be encrypted at rest. */ - fun value(value: String?) = apply { body.value(value) } - - /** Alias for calling [Builder.value] with `value.orElse(null)`. */ - fun value(value: Optional) = value(value.getOrNull()) - - /** - * Sets [Builder.value] to an arbitrary JSON value. - * - * You should usually call [Builder.value] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun value(value: JsonField) = apply { body.value(value) } - - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) - } - - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } - - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) - } - - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } - - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } - - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } - - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(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 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) - } - - /** - * Returns an immutable instance of [EnvVarReplaceParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * .objectId() - * .objectType() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): EnvVarReplaceParams = - EnvVarReplaceParams( - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) - } - /** The type of the object the environment variable is scoped for */ class ObjectType @JsonCreator private constructor(private val value: JsonField) : Enum { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarRetrieveParams.kt index 2ff67112..00b5ca97 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarRetrieveParams.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers @@ -24,16 +23,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _pathParam(index: Int): String = - when (index) { - 0 -> envVarId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - fun toBuilder() = Builder().from(this) companion object { @@ -50,7 +39,6 @@ private constructor( } /** A builder for [EnvVarRetrieveParams]. */ - @NoAutoDetect class Builder internal constructor() { private var envVarId: String? = null @@ -185,6 +173,16 @@ private constructor( ) } + fun _pathParam(index: Int): String = + when (index) { + 0 -> envVarId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarUpdateParams.kt index a77e6e8c..a8f82c94 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarUpdateParams.kt @@ -6,18 +6,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -74,187 +72,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - fun _pathParam(index: Int): String = - when (index) { - 0 -> envVarId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("value") - @ExcludeMissing - private val value: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { - - /** - * The name of the environment variable - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun name(): String = name.getRequired("name") - - /** - * The value of the environment variable. Will be encrypted at rest. - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun value(): Optional = Optional.ofNullable(value.getNullable("value")) - - /** - * Returns the raw JSON value of [name]. - * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - - /** - * Returns the raw JSON value of [value]. - * - * Unlike [value], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } - - name() - value() - validated = true - } - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .name() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var name: JsonField? = null - private var value: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - name = body.name - value = body.value - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** The name of the environment variable */ - fun name(name: String) = name(JsonField.of(name)) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } - - /** The value of the environment variable. Will be encrypted at rest. */ - fun value(value: String?) = value(JsonField.ofNullable(value)) - - /** Alias for calling [Builder.value] with `value.orElse(null)`. */ - fun value(value: Optional) = value(value.getOrNull()) - - /** - * Sets [Builder.value] to an arbitrary JSON value. - * - * You should usually call [Builder.value] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun value(value: JsonField) = apply { this.value = value } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - 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) - } - - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body(checkRequired("name", name), value, additionalProperties.toImmutable()) - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Body && name == other.name && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, value, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Body{name=$name, value=$value, additionalProperties=$additionalProperties}" - } - fun toBuilder() = Builder().from(this) companion object { @@ -272,7 +89,6 @@ private constructor( } /** A builder for [EnvVarUpdateParams]. */ - @NoAutoDetect class Builder internal constructor() { private var envVarId: String? = null @@ -455,6 +271,192 @@ private constructor( ) } + @JvmSynthetic internal fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> envVarId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val name: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("value") @ExcludeMissing value: JsonField = JsonMissing.of(), + ) : this(name, value, mutableMapOf()) + + /** + * The name of the environment variable + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * The value of the environment variable. Will be encrypted at rest. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun value(): Optional = Optional.ofNullable(value.getNullable("value")) + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [value]. + * + * Unlike [value], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var name: JsonField? = null + private var value: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + name = body.name + value = body.value + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** The name of the environment variable */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** The value of the environment variable. Will be encrypted at rest. */ + fun value(value: String?) = value(JsonField.ofNullable(value)) + + /** Alias for calling [Builder.value] with `value.orElse(null)`. */ + fun value(value: Optional) = value(value.getOrNull()) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun value(value: JsonField) = apply { this.value = value } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body(checkRequired("name", name), value, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + name() + value() + validated = true + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && name == other.name && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(name, value, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{name=$name, value=$value, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt index 96d00635..9ce4d6a0 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt @@ -9,14 +9,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter @@ -30,6 +28,7 @@ import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -308,1398 +307,1432 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body + fun toBuilder() = Builder().from(this) - override fun _headers(): Headers = additionalHeaders + companion object { - override fun _queryParams(): QueryParams = additionalQueryParams + /** + * Returns a mutable builder for constructing an instance of [EvalCreateParams]. + * + * The following fields are required: + * ```java + * .data() + * .projectId() + * .scores() + * .task() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), - @JsonProperty("project_id") - @ExcludeMissing - private val projectId: JsonField = JsonMissing.of(), - @JsonProperty("scores") - @ExcludeMissing - private val scores: JsonField> = JsonMissing.of(), - @JsonProperty("task") @ExcludeMissing private val task: JsonField = JsonMissing.of(), - @JsonProperty("base_experiment_id") - @ExcludeMissing - private val baseExperimentId: JsonField = JsonMissing.of(), - @JsonProperty("base_experiment_name") - @ExcludeMissing - private val baseExperimentName: JsonField = JsonMissing.of(), - @JsonProperty("experiment_name") - @ExcludeMissing - private val experimentName: JsonField = JsonMissing.of(), - @JsonProperty("git_metadata_settings") - @ExcludeMissing - private val gitMetadataSettings: JsonField = JsonMissing.of(), - @JsonProperty("is_public") - @ExcludeMissing - private val isPublic: JsonField = JsonMissing.of(), - @JsonProperty("max_concurrency") - @ExcludeMissing - private val maxConcurrency: JsonField = JsonMissing.of(), - @JsonProperty("metadata") - @ExcludeMissing - private val metadata: JsonField = JsonMissing.of(), - @JsonProperty("parent") - @ExcludeMissing - private val parent: JsonField = JsonMissing.of(), - @JsonProperty("repo_info") - @ExcludeMissing - private val repoInfo: JsonField = JsonMissing.of(), - @JsonProperty("stream") - @ExcludeMissing - private val stream: JsonField = JsonMissing.of(), - @JsonProperty("timeout") - @ExcludeMissing - private val timeout: JsonField = JsonMissing.of(), - @JsonProperty("trial_count") - @ExcludeMissing - private val trialCount: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + /** A builder for [EvalCreateParams]. */ + class Builder internal constructor() { + + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(evalCreateParams: EvalCreateParams) = apply { + body = evalCreateParams.body.toBuilder() + additionalHeaders = evalCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = evalCreateParams.additionalQueryParams.toBuilder() + } + + /** The dataset to use */ + fun data(data: Data) = apply { body.data(data) } /** - * The dataset to use + * Sets [Builder.data] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + * You should usually call [Builder.data] with a well-typed [Data] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun data(): Data = data.getRequired("data") + fun data(data: JsonField) = apply { body.data(data) } + + /** Alias for calling [data] with `Data.ofDatasetId(datasetId)`. */ + fun data(datasetId: Data.DatasetId) = apply { body.data(datasetId) } + + /** Alias for calling [data] with `Data.ofProjectDatasetName(projectDatasetName)`. */ + fun data(projectDatasetName: Data.ProjectDatasetName) = apply { + body.data(projectDatasetName) + } + + /** Alias for calling [data] with `Data.ofDatasetRows(datasetRows)`. */ + fun data(datasetRows: Data.DatasetRows) = apply { body.data(datasetRows) } + + /** Unique identifier for the project to run the eval in */ + fun projectId(projectId: String) = apply { body.projectId(projectId) } /** - * Unique identifier for the project to run the eval in + * Sets [Builder.projectId] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + * You should usually call [Builder.projectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun projectId(): String = projectId.getRequired("project_id") + fun projectId(projectId: JsonField) = apply { body.projectId(projectId) } + + /** The functions to score the eval on */ + fun scores(scores: List) = apply { body.scores(scores) } /** - * The functions to score the eval on + * Sets [Builder.scores] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + * You should usually call [Builder.scores] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun scores(): List = scores.getRequired("scores") + fun scores(scores: JsonField>) = apply { body.scores(scores) } /** - * The function to evaluate + * Adds a single [Score] to [scores]. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + * @throws IllegalStateException if the field was previously set to a non-list. */ - fun task(): Task = task.getRequired("task") + fun addScore(score: Score) = apply { body.addScore(score) } + + /** Alias for calling [addScore] with `Score.ofFunctionId(functionId)`. */ + fun addScore(functionId: Score.FunctionId) = apply { body.addScore(functionId) } + + /** Alias for calling [addScore] with `Score.ofProjectSlug(projectSlug)`. */ + fun addScore(projectSlug: Score.ProjectSlug) = apply { body.addScore(projectSlug) } + + /** Alias for calling [addScore] with `Score.ofGlobalFunction(globalFunction)`. */ + fun addScore(globalFunction: Score.GlobalFunction) = apply { body.addScore(globalFunction) } + + /** Alias for calling [addScore] with `Score.ofPromptSessionId(promptSessionId)`. */ + fun addScore(promptSessionId: Score.PromptSessionId) = apply { + body.addScore(promptSessionId) + } + + /** Alias for calling [addScore] with `Score.ofInlineCode(inlineCode)`. */ + fun addScore(inlineCode: Score.InlineCode) = apply { body.addScore(inlineCode) } + + /** Alias for calling [addScore] with `Score.ofInlinePrompt(inlinePrompt)`. */ + fun addScore(inlinePrompt: Score.InlinePrompt) = apply { body.addScore(inlinePrompt) } + + /** The function to evaluate */ + fun task(task: Task) = apply { body.task(task) } /** - * An optional experiment id to use as a base. If specified, the new experiment will be - * summarized and compared to this experiment. + * Sets [Builder.task] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.task] with a well-typed [Task] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun baseExperimentId(): Optional = - Optional.ofNullable(baseExperimentId.getNullable("base_experiment_id")) + fun task(task: JsonField) = apply { body.task(task) } + + /** Alias for calling [task] with `Task.ofFunctionId(functionId)`. */ + fun task(functionId: Task.FunctionId) = apply { body.task(functionId) } + + /** Alias for calling [task] with `Task.ofProjectSlug(projectSlug)`. */ + fun task(projectSlug: Task.ProjectSlug) = apply { body.task(projectSlug) } + + /** Alias for calling [task] with `Task.ofGlobalFunction(globalFunction)`. */ + fun task(globalFunction: Task.GlobalFunction) = apply { body.task(globalFunction) } + + /** Alias for calling [task] with `Task.ofPromptSessionId(promptSessionId)`. */ + fun task(promptSessionId: Task.PromptSessionId) = apply { body.task(promptSessionId) } + + /** Alias for calling [task] with `Task.ofInlineCode(inlineCode)`. */ + fun task(inlineCode: Task.InlineCode) = apply { body.task(inlineCode) } + + /** Alias for calling [task] with `Task.ofInlinePrompt(inlinePrompt)`. */ + fun task(inlinePrompt: Task.InlinePrompt) = apply { body.task(inlinePrompt) } /** - * An optional experiment name to use as a base. If specified, the new experiment will be + * An optional experiment id to use as a base. If specified, the new experiment will be * summarized and compared to this experiment. - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). */ - fun baseExperimentName(): Optional = - Optional.ofNullable(baseExperimentName.getNullable("base_experiment_name")) + fun baseExperimentId(baseExperimentId: String?) = apply { + body.baseExperimentId(baseExperimentId) + } + + /** Alias for calling [Builder.baseExperimentId] with `baseExperimentId.orElse(null)`. */ + fun baseExperimentId(baseExperimentId: Optional) = + baseExperimentId(baseExperimentId.getOrNull()) /** - * An optional name for the experiment created by this eval. If it conflicts with an - * existing experiment, it will be suffixed with a unique identifier. + * Sets [Builder.baseExperimentId] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.baseExperimentId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun experimentName(): Optional = - Optional.ofNullable(experimentName.getNullable("experiment_name")) + fun baseExperimentId(baseExperimentId: JsonField) = apply { + body.baseExperimentId(baseExperimentId) + } /** - * Optional settings for collecting git metadata. By default, will collect all git metadata - * fields allowed in org-level settings. - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * An optional experiment name to use as a base. If specified, the new experiment will be + * summarized and compared to this experiment. */ - fun gitMetadataSettings(): Optional = - Optional.ofNullable(gitMetadataSettings.getNullable("git_metadata_settings")) + fun baseExperimentName(baseExperimentName: String?) = apply { + body.baseExperimentName(baseExperimentName) + } /** - * Whether the experiment should be public. Defaults to false. - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * Alias for calling [Builder.baseExperimentName] with `baseExperimentName.orElse(null)`. */ - fun isPublic(): Optional = Optional.ofNullable(isPublic.getNullable("is_public")) + fun baseExperimentName(baseExperimentName: Optional) = + baseExperimentName(baseExperimentName.getOrNull()) /** - * The maximum number of tasks/scorers that will be run concurrently. Defaults to undefined, - * in which case there is no max concurrency. + * Sets [Builder.baseExperimentName] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.baseExperimentName] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun maxConcurrency(): Optional = - Optional.ofNullable(maxConcurrency.getNullable("max_concurrency")) + fun baseExperimentName(baseExperimentName: JsonField) = apply { + body.baseExperimentName(baseExperimentName) + } /** - * Optional experiment-level metadata to store about the evaluation. You can later use this - * to slice & dice across experiments. - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * An optional name for the experiment created by this eval. If it conflicts with an + * existing experiment, it will be suffixed with a unique identifier. */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun experimentName(experimentName: String) = apply { body.experimentName(experimentName) } /** - * Options for tracing the evaluation + * Sets [Builder.experimentName] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.experimentName] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun parent(): Optional = Optional.ofNullable(parent.getNullable("parent")) + fun experimentName(experimentName: JsonField) = apply { + body.experimentName(experimentName) + } /** - * Metadata about the state of the repo when the experiment was created - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * Optional settings for collecting git metadata. By default, will collect all git metadata + * fields allowed in org-level settings. */ - fun repoInfo(): Optional = Optional.ofNullable(repoInfo.getNullable("repo_info")) + fun gitMetadataSettings(gitMetadataSettings: GitMetadataSettings?) = apply { + body.gitMetadataSettings(gitMetadataSettings) + } /** - * Whether to stream the results of the eval. If true, the request will return two events: - * one to indicate the experiment has started, and another upon completion. If false, the - * request will return the evaluation's summary upon completion. - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * Alias for calling [Builder.gitMetadataSettings] with `gitMetadataSettings.orElse(null)`. */ - fun stream(): Optional = Optional.ofNullable(stream.getNullable("stream")) + fun gitMetadataSettings(gitMetadataSettings: Optional) = + gitMetadataSettings(gitMetadataSettings.getOrNull()) /** - * The maximum duration, in milliseconds, to run the evaluation. Defaults to undefined, in - * which case there is no timeout. + * Sets [Builder.gitMetadataSettings] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.gitMetadataSettings] with a well-typed + * [GitMetadataSettings] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. */ - fun timeout(): Optional = Optional.ofNullable(timeout.getNullable("timeout")) + fun gitMetadataSettings(gitMetadataSettings: JsonField) = apply { + body.gitMetadataSettings(gitMetadataSettings) + } + + /** Whether the experiment should be public. Defaults to false. */ + fun isPublic(isPublic: Boolean?) = apply { body.isPublic(isPublic) } /** - * The number of times to run the evaluator per input. This is useful for evaluating - * applications that have non-deterministic behavior and gives you both a stronger aggregate - * measure and a sense of the variance in the results. + * Alias for [Builder.isPublic]. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * This unboxed primitive overload exists for backwards compatibility. */ - fun trialCount(): Optional = - Optional.ofNullable(trialCount.getNullable("trial_count")) + fun isPublic(isPublic: Boolean) = isPublic(isPublic as Boolean?) + + /** Alias for calling [Builder.isPublic] with `isPublic.orElse(null)`. */ + fun isPublic(isPublic: Optional) = isPublic(isPublic.getOrNull()) /** - * Returns the raw JSON value of [data]. + * Sets [Builder.isPublic] to an arbitrary JSON value. * - * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.isPublic] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data + fun isPublic(isPublic: JsonField) = apply { body.isPublic(isPublic) } /** - * Returns the raw JSON value of [projectId]. - * - * Unlike [projectId], this method doesn't throw if the JSON field has an unexpected type. + * The maximum number of tasks/scorers that will be run concurrently. Defaults to undefined, + * in which case there is no max concurrency. */ - @JsonProperty("project_id") @ExcludeMissing fun _projectId(): JsonField = projectId + fun maxConcurrency(maxConcurrency: Double?) = apply { body.maxConcurrency(maxConcurrency) } /** - * Returns the raw JSON value of [scores]. + * Alias for [Builder.maxConcurrency]. * - * Unlike [scores], this method doesn't throw if the JSON field has an unexpected type. + * This unboxed primitive overload exists for backwards compatibility. */ - @JsonProperty("scores") @ExcludeMissing fun _scores(): JsonField> = scores + fun maxConcurrency(maxConcurrency: Double) = maxConcurrency(maxConcurrency as Double?) + + /** Alias for calling [Builder.maxConcurrency] with `maxConcurrency.orElse(null)`. */ + fun maxConcurrency(maxConcurrency: Optional) = + maxConcurrency(maxConcurrency.getOrNull()) /** - * Returns the raw JSON value of [task]. + * Sets [Builder.maxConcurrency] to an arbitrary JSON value. * - * Unlike [task], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.maxConcurrency] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("task") @ExcludeMissing fun _task(): JsonField = task + fun maxConcurrency(maxConcurrency: JsonField) = apply { + body.maxConcurrency(maxConcurrency) + } /** - * Returns the raw JSON value of [baseExperimentId]. - * - * Unlike [baseExperimentId], this method doesn't throw if the JSON field has an unexpected - * type. + * Optional experiment-level metadata to store about the evaluation. You can later use this + * to slice & dice across experiments. */ - @JsonProperty("base_experiment_id") - @ExcludeMissing - fun _baseExperimentId(): JsonField = baseExperimentId + fun metadata(metadata: Metadata) = apply { body.metadata(metadata) } /** - * Returns the raw JSON value of [baseExperimentName]. + * Sets [Builder.metadata] to an arbitrary JSON value. * - * Unlike [baseExperimentName], this method doesn't throw if the JSON field has an - * unexpected type. + * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("base_experiment_name") - @ExcludeMissing - fun _baseExperimentName(): JsonField = baseExperimentName + fun metadata(metadata: JsonField) = apply { body.metadata(metadata) } + + /** Options for tracing the evaluation */ + fun parent(parent: Parent) = apply { body.parent(parent) } /** - * Returns the raw JSON value of [experimentName]. + * Sets [Builder.parent] to an arbitrary JSON value. * - * Unlike [experimentName], this method doesn't throw if the JSON field has an unexpected - * type. + * You should usually call [Builder.parent] with a well-typed [Parent] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("experiment_name") - @ExcludeMissing - fun _experimentName(): JsonField = experimentName + fun parent(parent: JsonField) = apply { body.parent(parent) } + + /** Alias for calling [parent] with `Parent.ofSpanParentStruct(spanParentStruct)`. */ + fun parent(spanParentStruct: Parent.SpanParentStruct) = apply { + body.parent(spanParentStruct) + } + + /** Alias for calling [parent] with `Parent.ofString(string)`. */ + fun parent(string: String) = apply { body.parent(string) } + + /** Metadata about the state of the repo when the experiment was created */ + fun repoInfo(repoInfo: RepoInfo?) = apply { body.repoInfo(repoInfo) } + + /** Alias for calling [Builder.repoInfo] with `repoInfo.orElse(null)`. */ + fun repoInfo(repoInfo: Optional) = repoInfo(repoInfo.getOrNull()) /** - * Returns the raw JSON value of [gitMetadataSettings]. + * Sets [Builder.repoInfo] to an arbitrary JSON value. * - * Unlike [gitMetadataSettings], this method doesn't throw if the JSON field has an - * unexpected type. + * You should usually call [Builder.repoInfo] with a well-typed [RepoInfo] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("git_metadata_settings") - @ExcludeMissing - fun _gitMetadataSettings(): JsonField = gitMetadataSettings + fun repoInfo(repoInfo: JsonField) = apply { body.repoInfo(repoInfo) } /** - * Returns the raw JSON value of [isPublic]. - * - * Unlike [isPublic], this method doesn't throw if the JSON field has an unexpected type. + * Whether to stream the results of the eval. If true, the request will return two events: + * one to indicate the experiment has started, and another upon completion. If false, the + * request will return the evaluation's summary upon completion. */ - @JsonProperty("is_public") @ExcludeMissing fun _isPublic(): JsonField = isPublic + fun stream(stream: Boolean) = apply { body.stream(stream) } /** - * Returns the raw JSON value of [maxConcurrency]. + * Sets [Builder.stream] to an arbitrary JSON value. * - * Unlike [maxConcurrency], this method doesn't throw if the JSON field has an unexpected - * type. + * You should usually call [Builder.stream] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("max_concurrency") - @ExcludeMissing - fun _maxConcurrency(): JsonField = maxConcurrency + fun stream(stream: JsonField) = apply { body.stream(stream) } /** - * Returns the raw JSON value of [metadata]. - * - * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + * The maximum duration, in milliseconds, to run the evaluation. Defaults to undefined, in + * which case there is no timeout. */ - @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + fun timeout(timeout: Double?) = apply { body.timeout(timeout) } /** - * Returns the raw JSON value of [parent]. + * Alias for [Builder.timeout]. * - * Unlike [parent], this method doesn't throw if the JSON field has an unexpected type. + * This unboxed primitive overload exists for backwards compatibility. */ - @JsonProperty("parent") @ExcludeMissing fun _parent(): JsonField = parent + fun timeout(timeout: Double) = timeout(timeout as Double?) + + /** Alias for calling [Builder.timeout] with `timeout.orElse(null)`. */ + fun timeout(timeout: Optional) = timeout(timeout.getOrNull()) /** - * Returns the raw JSON value of [repoInfo]. + * Sets [Builder.timeout] to an arbitrary JSON value. * - * Unlike [repoInfo], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.timeout] with a well-typed [Double] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("repo_info") @ExcludeMissing fun _repoInfo(): JsonField = repoInfo + fun timeout(timeout: JsonField) = apply { body.timeout(timeout) } /** - * Returns the raw JSON value of [stream]. - * - * Unlike [stream], this method doesn't throw if the JSON field has an unexpected type. + * The number of times to run the evaluator per input. This is useful for evaluating + * applications that have non-deterministic behavior and gives you both a stronger aggregate + * measure and a sense of the variance in the results. */ - @JsonProperty("stream") @ExcludeMissing fun _stream(): JsonField = stream + fun trialCount(trialCount: Double?) = apply { body.trialCount(trialCount) } /** - * Returns the raw JSON value of [timeout]. + * Alias for [Builder.trialCount]. * - * Unlike [timeout], this method doesn't throw if the JSON field has an unexpected type. + * This unboxed primitive overload exists for backwards compatibility. */ - @JsonProperty("timeout") @ExcludeMissing fun _timeout(): JsonField = timeout + fun trialCount(trialCount: Double) = trialCount(trialCount as Double?) + + /** Alias for calling [Builder.trialCount] with `trialCount.orElse(null)`. */ + fun trialCount(trialCount: Optional) = trialCount(trialCount.getOrNull()) /** - * Returns the raw JSON value of [trialCount]. + * Sets [Builder.trialCount] to an arbitrary JSON value. * - * Unlike [trialCount], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.trialCount] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("trial_count") - @ExcludeMissing - fun _trialCount(): JsonField = trialCount + fun trialCount(trialCount: JsonField) = apply { body.trialCount(trialCount) } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } - private var validated: Boolean = false + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } - fun validate(): Body = apply { - if (validated) { - return@apply + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) } - data().validate() - projectId() - scores().forEach { it.validate() } - task().validate() - baseExperimentId() - baseExperimentName() - experimentName() - gitMetadataSettings().ifPresent { it.validate() } - isPublic() - maxConcurrency() - metadata().ifPresent { it.validate() } - parent().ifPresent { it.validate() } - repoInfo().ifPresent { it.validate() } - stream() - timeout() - trialCount() - validated = true - } + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - fun toBuilder() = Builder().from(this) + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } - companion object { + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .data() - * .projectId() - * .scores() - * .task() - * ``` - */ - @JvmStatic fun builder() = Builder() + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - /** A builder for [Body]. */ - class Builder internal constructor() { + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } - private var data: JsonField? = null - private var projectId: JsonField? = null - private var scores: JsonField>? = null - private var task: JsonField? = null - private var baseExperimentId: JsonField = JsonMissing.of() - private var baseExperimentName: JsonField = JsonMissing.of() - private var experimentName: JsonField = JsonMissing.of() - private var gitMetadataSettings: JsonField = JsonMissing.of() - private var isPublic: JsonField = JsonMissing.of() - private var maxConcurrency: JsonField = JsonMissing.of() - private var metadata: JsonField = JsonMissing.of() - private var parent: JsonField = JsonMissing.of() - private var repoInfo: JsonField = JsonMissing.of() - private var stream: JsonField = JsonMissing.of() - private var timeout: JsonField = JsonMissing.of() - private var trialCount: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - data = body.data - projectId = body.projectId - scores = body.scores.map { it.toMutableList() } - task = body.task - baseExperimentId = body.baseExperimentId - baseExperimentName = body.baseExperimentName - experimentName = body.experimentName - gitMetadataSettings = body.gitMetadataSettings - isPublic = body.isPublic - maxConcurrency = body.maxConcurrency - metadata = body.metadata - parent = body.parent - repoInfo = body.repoInfo - stream = body.stream - timeout = body.timeout - trialCount = body.trialCount - additionalProperties = body.additionalProperties.toMutableMap() - } + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - /** The dataset to use */ - fun data(data: Data) = data(JsonField.of(data)) + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** - * Sets [Builder.data] to an arbitrary JSON value. - * - * You should usually call [Builder.data] with a well-typed [Data] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun data(data: JsonField) = apply { this.data = data } + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** Alias for calling [data] with `Data.ofDatasetId(datasetId)`. */ - fun data(datasetId: Data.DatasetId) = data(Data.ofDatasetId(datasetId)) + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - /** Alias for calling [data] with `Data.ofProjectDatasetName(projectDatasetName)`. */ - fun data(projectDatasetName: Data.ProjectDatasetName) = - data(Data.ofProjectDatasetName(projectDatasetName)) + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** Alias for calling [data] with `Data.ofDatasetRows(datasetRows)`. */ - fun data(datasetRows: Data.DatasetRows) = data(Data.ofDatasetRows(datasetRows)) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** Unique identifier for the project to run the eval in */ - fun projectId(projectId: String) = projectId(JsonField.of(projectId)) + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Sets [Builder.projectId] to an arbitrary JSON value. - * - * You should usually call [Builder.projectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun projectId(projectId: JsonField) = apply { this.projectId = projectId } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } - /** The functions to score the eval on */ - fun scores(scores: List) = scores(JsonField.of(scores)) + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } - /** - * Sets [Builder.scores] to an arbitrary JSON value. - * - * You should usually call [Builder.scores] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun scores(scores: JsonField>) = apply { - this.scores = scores.map { it.toMutableList() } - } + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - /** - * Adds a single [Score] to [scores]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addScore(score: Score) = apply { - scores = - (scores ?: JsonField.of(mutableListOf())).also { - checkKnown("scores", it).add(score) - } - } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - /** Alias for calling [addScore] with `Score.ofFunctionId(functionId)`. */ - fun addScore(functionId: Score.FunctionId) = addScore(Score.ofFunctionId(functionId)) + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } - /** Alias for calling [addScore] with `Score.ofProjectSlug(projectSlug)`. */ - fun addScore(projectSlug: Score.ProjectSlug) = - addScore(Score.ofProjectSlug(projectSlug)) + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } - /** Alias for calling [addScore] with `Score.ofGlobalFunction(globalFunction)`. */ - fun addScore(globalFunction: Score.GlobalFunction) = - addScore(Score.ofGlobalFunction(globalFunction)) + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } - /** Alias for calling [addScore] with `Score.ofPromptSessionId(promptSessionId)`. */ - fun addScore(promptSessionId: Score.PromptSessionId) = - addScore(Score.ofPromptSessionId(promptSessionId)) + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } - /** Alias for calling [addScore] with `Score.ofInlineCode(inlineCode)`. */ - fun addScore(inlineCode: Score.InlineCode) = addScore(Score.ofInlineCode(inlineCode)) + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } - /** Alias for calling [addScore] with `Score.ofInlinePrompt(inlinePrompt)`. */ - fun addScore(inlinePrompt: Score.InlinePrompt) = - addScore(Score.ofInlinePrompt(inlinePrompt)) + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } - /** The function to evaluate */ - fun task(task: Task) = task(JsonField.of(task)) + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - /** - * Sets [Builder.task] to an arbitrary JSON value. - * - * You should usually call [Builder.task] with a well-typed [Task] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun task(task: JsonField) = apply { this.task = task } + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - /** Alias for calling [task] with `Task.ofFunctionId(functionId)`. */ - fun task(functionId: Task.FunctionId) = task(Task.ofFunctionId(functionId)) + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - /** Alias for calling [task] with `Task.ofProjectSlug(projectSlug)`. */ - fun task(projectSlug: Task.ProjectSlug) = task(Task.ofProjectSlug(projectSlug)) + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } - /** Alias for calling [task] with `Task.ofGlobalFunction(globalFunction)`. */ - fun task(globalFunction: Task.GlobalFunction) = - task(Task.ofGlobalFunction(globalFunction)) + /** + * Returns an immutable instance of [EvalCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .projectId() + * .scores() + * .task() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EvalCreateParams = + EvalCreateParams(body.build(), additionalHeaders.build(), additionalQueryParams.build()) + } - /** Alias for calling [task] with `Task.ofPromptSessionId(promptSessionId)`. */ - fun task(promptSessionId: Task.PromptSessionId) = - task(Task.ofPromptSessionId(promptSessionId)) + @JvmSynthetic internal fun _body(): Body = body - /** Alias for calling [task] with `Task.ofInlineCode(inlineCode)`. */ - fun task(inlineCode: Task.InlineCode) = task(Task.ofInlineCode(inlineCode)) + override fun _headers(): Headers = additionalHeaders - /** Alias for calling [task] with `Task.ofInlinePrompt(inlinePrompt)`. */ - fun task(inlinePrompt: Task.InlinePrompt) = task(Task.ofInlinePrompt(inlinePrompt)) + override fun _queryParams(): QueryParams = additionalQueryParams - /** - * An optional experiment id to use as a base. If specified, the new experiment will be - * summarized and compared to this experiment. - */ - fun baseExperimentId(baseExperimentId: String?) = - baseExperimentId(JsonField.ofNullable(baseExperimentId)) + class Body + private constructor( + private val data: JsonField, + private val projectId: JsonField, + private val scores: JsonField>, + private val task: JsonField, + private val baseExperimentId: JsonField, + private val baseExperimentName: JsonField, + private val experimentName: JsonField, + private val gitMetadataSettings: JsonField, + private val isPublic: JsonField, + private val maxConcurrency: JsonField, + private val metadata: JsonField, + private val parent: JsonField, + private val repoInfo: JsonField, + private val stream: JsonField, + private val timeout: JsonField, + private val trialCount: JsonField, + private val additionalProperties: MutableMap, + ) { - /** - * Alias for calling [Builder.baseExperimentId] with `baseExperimentId.orElse(null)`. - */ - fun baseExperimentId(baseExperimentId: Optional) = - baseExperimentId(baseExperimentId.getOrNull()) + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("scores") + @ExcludeMissing + scores: JsonField> = JsonMissing.of(), + @JsonProperty("task") @ExcludeMissing task: JsonField = JsonMissing.of(), + @JsonProperty("base_experiment_id") + @ExcludeMissing + baseExperimentId: JsonField = JsonMissing.of(), + @JsonProperty("base_experiment_name") + @ExcludeMissing + baseExperimentName: JsonField = JsonMissing.of(), + @JsonProperty("experiment_name") + @ExcludeMissing + experimentName: JsonField = JsonMissing.of(), + @JsonProperty("git_metadata_settings") + @ExcludeMissing + gitMetadataSettings: JsonField = JsonMissing.of(), + @JsonProperty("is_public") + @ExcludeMissing + isPublic: JsonField = JsonMissing.of(), + @JsonProperty("max_concurrency") + @ExcludeMissing + maxConcurrency: JsonField = JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("parent") @ExcludeMissing parent: JsonField = JsonMissing.of(), + @JsonProperty("repo_info") + @ExcludeMissing + repoInfo: JsonField = JsonMissing.of(), + @JsonProperty("stream") @ExcludeMissing stream: JsonField = JsonMissing.of(), + @JsonProperty("timeout") @ExcludeMissing timeout: JsonField = JsonMissing.of(), + @JsonProperty("trial_count") + @ExcludeMissing + trialCount: JsonField = JsonMissing.of(), + ) : this( + data, + projectId, + scores, + task, + baseExperimentId, + baseExperimentName, + experimentName, + gitMetadataSettings, + isPublic, + maxConcurrency, + metadata, + parent, + repoInfo, + stream, + timeout, + trialCount, + mutableMapOf(), + ) - /** - * Sets [Builder.baseExperimentId] to an arbitrary JSON value. - * - * You should usually call [Builder.baseExperimentId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun baseExperimentId(baseExperimentId: JsonField) = apply { - this.baseExperimentId = baseExperimentId - } + /** + * The dataset to use + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): Data = data.getRequired("data") - /** - * An optional experiment name to use as a base. If specified, the new experiment will - * be summarized and compared to this experiment. - */ - fun baseExperimentName(baseExperimentName: String?) = - baseExperimentName(JsonField.ofNullable(baseExperimentName)) - - /** - * Alias for calling [Builder.baseExperimentName] with - * `baseExperimentName.orElse(null)`. - */ - fun baseExperimentName(baseExperimentName: Optional) = - baseExperimentName(baseExperimentName.getOrNull()) - - /** - * Sets [Builder.baseExperimentName] to an arbitrary JSON value. - * - * You should usually call [Builder.baseExperimentName] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun baseExperimentName(baseExperimentName: JsonField) = apply { - this.baseExperimentName = baseExperimentName - } - - /** - * An optional name for the experiment created by this eval. If it conflicts with an - * existing experiment, it will be suffixed with a unique identifier. - */ - fun experimentName(experimentName: String) = - experimentName(JsonField.of(experimentName)) - - /** - * Sets [Builder.experimentName] to an arbitrary JSON value. - * - * You should usually call [Builder.experimentName] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun experimentName(experimentName: JsonField) = apply { - this.experimentName = experimentName - } - - /** - * Optional settings for collecting git metadata. By default, will collect all git - * metadata fields allowed in org-level settings. - */ - fun gitMetadataSettings(gitMetadataSettings: GitMetadataSettings?) = - gitMetadataSettings(JsonField.ofNullable(gitMetadataSettings)) - - /** - * Alias for calling [Builder.gitMetadataSettings] with - * `gitMetadataSettings.orElse(null)`. - */ - fun gitMetadataSettings(gitMetadataSettings: Optional) = - gitMetadataSettings(gitMetadataSettings.getOrNull()) - - /** - * Sets [Builder.gitMetadataSettings] to an arbitrary JSON value. - * - * You should usually call [Builder.gitMetadataSettings] with a well-typed - * [GitMetadataSettings] value instead. This method is primarily for setting the field - * to an undocumented or not yet supported value. - */ - fun gitMetadataSettings(gitMetadataSettings: JsonField) = apply { - this.gitMetadataSettings = gitMetadataSettings - } - - /** Whether the experiment should be public. Defaults to false. */ - fun isPublic(isPublic: Boolean?) = isPublic(JsonField.ofNullable(isPublic)) - - /** - * Alias for [Builder.isPublic]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun isPublic(isPublic: Boolean) = isPublic(isPublic as Boolean?) - - /** Alias for calling [Builder.isPublic] with `isPublic.orElse(null)`. */ - fun isPublic(isPublic: Optional) = isPublic(isPublic.getOrNull()) - - /** - * Sets [Builder.isPublic] to an arbitrary JSON value. - * - * You should usually call [Builder.isPublic] with a well-typed [Boolean] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun isPublic(isPublic: JsonField) = apply { this.isPublic = isPublic } - - /** - * The maximum number of tasks/scorers that will be run concurrently. Defaults to - * undefined, in which case there is no max concurrency. - */ - fun maxConcurrency(maxConcurrency: Double?) = - maxConcurrency(JsonField.ofNullable(maxConcurrency)) - - /** - * Alias for [Builder.maxConcurrency]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun maxConcurrency(maxConcurrency: Double) = maxConcurrency(maxConcurrency as Double?) - - /** Alias for calling [Builder.maxConcurrency] with `maxConcurrency.orElse(null)`. */ - fun maxConcurrency(maxConcurrency: Optional) = - maxConcurrency(maxConcurrency.getOrNull()) - - /** - * Sets [Builder.maxConcurrency] to an arbitrary JSON value. - * - * You should usually call [Builder.maxConcurrency] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun maxConcurrency(maxConcurrency: JsonField) = apply { - this.maxConcurrency = maxConcurrency - } - - /** - * Optional experiment-level metadata to store about the evaluation. You can later use - * this to slice & dice across experiments. - */ - fun metadata(metadata: Metadata) = metadata(JsonField.of(metadata)) - - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - - /** Options for tracing the evaluation */ - fun parent(parent: Parent) = parent(JsonField.of(parent)) - - /** - * Sets [Builder.parent] to an arbitrary JSON value. - * - * You should usually call [Builder.parent] with a well-typed [Parent] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun parent(parent: JsonField) = apply { this.parent = parent } - - /** Alias for calling [parent] with `Parent.ofSpanParentStruct(spanParentStruct)`. */ - fun parent(spanParentStruct: Parent.SpanParentStruct) = - parent(Parent.ofSpanParentStruct(spanParentStruct)) - - /** Alias for calling [parent] with `Parent.ofString(string)`. */ - fun parent(string: String) = parent(Parent.ofString(string)) - - /** Metadata about the state of the repo when the experiment was created */ - fun repoInfo(repoInfo: RepoInfo?) = repoInfo(JsonField.ofNullable(repoInfo)) - - /** Alias for calling [Builder.repoInfo] with `repoInfo.orElse(null)`. */ - fun repoInfo(repoInfo: Optional) = repoInfo(repoInfo.getOrNull()) - - /** - * Sets [Builder.repoInfo] to an arbitrary JSON value. - * - * You should usually call [Builder.repoInfo] with a well-typed [RepoInfo] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun repoInfo(repoInfo: JsonField) = apply { this.repoInfo = repoInfo } - - /** - * Whether to stream the results of the eval. If true, the request will return two - * events: one to indicate the experiment has started, and another upon completion. If - * false, the request will return the evaluation's summary upon completion. - */ - fun stream(stream: Boolean) = stream(JsonField.of(stream)) + /** + * Unique identifier for the project to run the eval in + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun projectId(): String = projectId.getRequired("project_id") - /** - * Sets [Builder.stream] to an arbitrary JSON value. - * - * You should usually call [Builder.stream] with a well-typed [Boolean] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun stream(stream: JsonField) = apply { this.stream = stream } + /** + * The functions to score the eval on + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun scores(): List = scores.getRequired("scores") - /** - * The maximum duration, in milliseconds, to run the evaluation. Defaults to undefined, - * in which case there is no timeout. - */ - fun timeout(timeout: Double?) = timeout(JsonField.ofNullable(timeout)) + /** + * The function to evaluate + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun task(): Task = task.getRequired("task") - /** - * Alias for [Builder.timeout]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun timeout(timeout: Double) = timeout(timeout as Double?) + /** + * An optional experiment id to use as a base. If specified, the new experiment will be + * summarized and compared to this experiment. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun baseExperimentId(): Optional = + Optional.ofNullable(baseExperimentId.getNullable("base_experiment_id")) - /** Alias for calling [Builder.timeout] with `timeout.orElse(null)`. */ - fun timeout(timeout: Optional) = timeout(timeout.getOrNull()) + /** + * An optional experiment name to use as a base. If specified, the new experiment will be + * summarized and compared to this experiment. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun baseExperimentName(): Optional = + Optional.ofNullable(baseExperimentName.getNullable("base_experiment_name")) - /** - * Sets [Builder.timeout] to an arbitrary JSON value. - * - * You should usually call [Builder.timeout] with a well-typed [Double] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun timeout(timeout: JsonField) = apply { this.timeout = timeout } + /** + * An optional name for the experiment created by this eval. If it conflicts with an + * existing experiment, it will be suffixed with a unique identifier. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun experimentName(): Optional = + Optional.ofNullable(experimentName.getNullable("experiment_name")) - /** - * The number of times to run the evaluator per input. This is useful for evaluating - * applications that have non-deterministic behavior and gives you both a stronger - * aggregate measure and a sense of the variance in the results. - */ - fun trialCount(trialCount: Double?) = trialCount(JsonField.ofNullable(trialCount)) + /** + * Optional settings for collecting git metadata. By default, will collect all git metadata + * fields allowed in org-level settings. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun gitMetadataSettings(): Optional = + Optional.ofNullable(gitMetadataSettings.getNullable("git_metadata_settings")) - /** - * Alias for [Builder.trialCount]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun trialCount(trialCount: Double) = trialCount(trialCount as Double?) + /** + * Whether the experiment should be public. Defaults to false. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun isPublic(): Optional = Optional.ofNullable(isPublic.getNullable("is_public")) - /** Alias for calling [Builder.trialCount] with `trialCount.orElse(null)`. */ - fun trialCount(trialCount: Optional) = trialCount(trialCount.getOrNull()) + /** + * The maximum number of tasks/scorers that will be run concurrently. Defaults to undefined, + * in which case there is no max concurrency. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun maxConcurrency(): Optional = + Optional.ofNullable(maxConcurrency.getNullable("max_concurrency")) - /** - * Sets [Builder.trialCount] to an arbitrary JSON value. - * - * You should usually call [Builder.trialCount] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun trialCount(trialCount: JsonField) = apply { this.trialCount = trialCount } + /** + * Optional experiment-level metadata to store about the evaluation. You can later use this + * to slice & dice across experiments. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + /** + * Options for tracing the evaluation + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun parent(): Optional = Optional.ofNullable(parent.getNullable("parent")) - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + /** + * Metadata about the state of the repo when the experiment was created + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun repoInfo(): Optional = Optional.ofNullable(repoInfo.getNullable("repo_info")) - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + /** + * Whether to stream the results of the eval. If true, the request will return two events: + * one to indicate the experiment has started, and another upon completion. If false, the + * request will return the evaluation's summary upon completion. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun stream(): Optional = Optional.ofNullable(stream.getNullable("stream")) - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + /** + * The maximum duration, in milliseconds, to run the evaluation. Defaults to undefined, in + * which case there is no timeout. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun timeout(): Optional = Optional.ofNullable(timeout.getNullable("timeout")) - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** + * The number of times to run the evaluator per input. This is useful for evaluating + * applications that have non-deterministic behavior and gives you both a stronger aggregate + * measure and a sense of the variance in the results. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun trialCount(): Optional = + Optional.ofNullable(trialCount.getNullable("trial_count")) - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .data() - * .projectId() - * .scores() - * .task() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("data", data), - checkRequired("projectId", projectId), - checkRequired("scores", scores).map { it.toImmutable() }, - checkRequired("task", task), - baseExperimentId, - baseExperimentName, - experimentName, - gitMetadataSettings, - isPublic, - maxConcurrency, - metadata, - parent, - repoInfo, - stream, - timeout, - trialCount, - additionalProperties.toImmutable(), - ) - } + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Returns the raw JSON value of [projectId]. + * + * Unlike [projectId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("project_id") @ExcludeMissing fun _projectId(): JsonField = projectId - return /* spotless:off */ other is Body && data == other.data && projectId == other.projectId && scores == other.scores && task == other.task && baseExperimentId == other.baseExperimentId && baseExperimentName == other.baseExperimentName && experimentName == other.experimentName && gitMetadataSettings == other.gitMetadataSettings && isPublic == other.isPublic && maxConcurrency == other.maxConcurrency && metadata == other.metadata && parent == other.parent && repoInfo == other.repoInfo && stream == other.stream && timeout == other.timeout && trialCount == other.trialCount && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Returns the raw JSON value of [scores]. + * + * Unlike [scores], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("scores") @ExcludeMissing fun _scores(): JsonField> = scores - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(data, projectId, scores, task, baseExperimentId, baseExperimentName, experimentName, gitMetadataSettings, isPublic, maxConcurrency, metadata, parent, repoInfo, stream, timeout, trialCount, additionalProperties) } - /* spotless:on */ + /** + * Returns the raw JSON value of [task]. + * + * Unlike [task], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("task") @ExcludeMissing fun _task(): JsonField = task - override fun hashCode(): Int = hashCode + /** + * Returns the raw JSON value of [baseExperimentId]. + * + * Unlike [baseExperimentId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("base_experiment_id") + @ExcludeMissing + fun _baseExperimentId(): JsonField = baseExperimentId - override fun toString() = - "Body{data=$data, projectId=$projectId, scores=$scores, task=$task, baseExperimentId=$baseExperimentId, baseExperimentName=$baseExperimentName, experimentName=$experimentName, gitMetadataSettings=$gitMetadataSettings, isPublic=$isPublic, maxConcurrency=$maxConcurrency, metadata=$metadata, parent=$parent, repoInfo=$repoInfo, stream=$stream, timeout=$timeout, trialCount=$trialCount, additionalProperties=$additionalProperties}" - } + /** + * Returns the raw JSON value of [baseExperimentName]. + * + * Unlike [baseExperimentName], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("base_experiment_name") + @ExcludeMissing + fun _baseExperimentName(): JsonField = baseExperimentName - fun toBuilder() = Builder().from(this) + /** + * Returns the raw JSON value of [experimentName]. + * + * Unlike [experimentName], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("experiment_name") + @ExcludeMissing + fun _experimentName(): JsonField = experimentName - companion object { + /** + * Returns the raw JSON value of [gitMetadataSettings]. + * + * Unlike [gitMetadataSettings], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("git_metadata_settings") + @ExcludeMissing + fun _gitMetadataSettings(): JsonField = gitMetadataSettings /** - * Returns a mutable builder for constructing an instance of [EvalCreateParams]. + * Returns the raw JSON value of [isPublic]. * - * The following fields are required: - * ```java - * .data() - * .projectId() - * .scores() - * .task() - * ``` + * Unlike [isPublic], this method doesn't throw if the JSON field has an unexpected type. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [EvalCreateParams]. */ - @NoAutoDetect - class Builder internal constructor() { - - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - - @JvmSynthetic - internal fun from(evalCreateParams: EvalCreateParams) = apply { - body = evalCreateParams.body.toBuilder() - additionalHeaders = evalCreateParams.additionalHeaders.toBuilder() - additionalQueryParams = evalCreateParams.additionalQueryParams.toBuilder() - } - - /** The dataset to use */ - fun data(data: Data) = apply { body.data(data) } + @JsonProperty("is_public") @ExcludeMissing fun _isPublic(): JsonField = isPublic /** - * Sets [Builder.data] to an arbitrary JSON value. + * Returns the raw JSON value of [maxConcurrency]. * - * You should usually call [Builder.data] with a well-typed [Data] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [maxConcurrency], this method doesn't throw if the JSON field has an unexpected + * type. */ - fun data(data: JsonField) = apply { body.data(data) } - - /** Alias for calling [data] with `Data.ofDatasetId(datasetId)`. */ - fun data(datasetId: Data.DatasetId) = apply { body.data(datasetId) } - - /** Alias for calling [data] with `Data.ofProjectDatasetName(projectDatasetName)`. */ - fun data(projectDatasetName: Data.ProjectDatasetName) = apply { - body.data(projectDatasetName) - } + @JsonProperty("max_concurrency") + @ExcludeMissing + fun _maxConcurrency(): JsonField = maxConcurrency - /** Alias for calling [data] with `Data.ofDatasetRows(datasetRows)`. */ - fun data(datasetRows: Data.DatasetRows) = apply { body.data(datasetRows) } + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata - /** Unique identifier for the project to run the eval in */ - fun projectId(projectId: String) = apply { body.projectId(projectId) } + /** + * Returns the raw JSON value of [parent]. + * + * Unlike [parent], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("parent") @ExcludeMissing fun _parent(): JsonField = parent /** - * Sets [Builder.projectId] to an arbitrary JSON value. + * Returns the raw JSON value of [repoInfo]. * - * You should usually call [Builder.projectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [repoInfo], this method doesn't throw if the JSON field has an unexpected type. */ - fun projectId(projectId: JsonField) = apply { body.projectId(projectId) } + @JsonProperty("repo_info") @ExcludeMissing fun _repoInfo(): JsonField = repoInfo - /** The functions to score the eval on */ - fun scores(scores: List) = apply { body.scores(scores) } + /** + * Returns the raw JSON value of [stream]. + * + * Unlike [stream], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("stream") @ExcludeMissing fun _stream(): JsonField = stream /** - * Sets [Builder.scores] to an arbitrary JSON value. + * Returns the raw JSON value of [timeout]. * - * You should usually call [Builder.scores] with a well-typed `List` value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [timeout], this method doesn't throw if the JSON field has an unexpected type. */ - fun scores(scores: JsonField>) = apply { body.scores(scores) } + @JsonProperty("timeout") @ExcludeMissing fun _timeout(): JsonField = timeout /** - * Adds a single [Score] to [scores]. + * Returns the raw JSON value of [trialCount]. * - * @throws IllegalStateException if the field was previously set to a non-list. + * Unlike [trialCount], this method doesn't throw if the JSON field has an unexpected type. */ - fun addScore(score: Score) = apply { body.addScore(score) } + @JsonProperty("trial_count") + @ExcludeMissing + fun _trialCount(): JsonField = trialCount - /** Alias for calling [addScore] with `Score.ofFunctionId(functionId)`. */ - fun addScore(functionId: Score.FunctionId) = apply { body.addScore(functionId) } + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - /** Alias for calling [addScore] with `Score.ofProjectSlug(projectSlug)`. */ - fun addScore(projectSlug: Score.ProjectSlug) = apply { body.addScore(projectSlug) } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - /** Alias for calling [addScore] with `Score.ofGlobalFunction(globalFunction)`. */ - fun addScore(globalFunction: Score.GlobalFunction) = apply { body.addScore(globalFunction) } + fun toBuilder() = Builder().from(this) - /** Alias for calling [addScore] with `Score.ofPromptSessionId(promptSessionId)`. */ - fun addScore(promptSessionId: Score.PromptSessionId) = apply { - body.addScore(promptSessionId) + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .data() + * .projectId() + * .scores() + * .task() + * ``` + */ + @JvmStatic fun builder() = Builder() } - /** Alias for calling [addScore] with `Score.ofInlineCode(inlineCode)`. */ - fun addScore(inlineCode: Score.InlineCode) = apply { body.addScore(inlineCode) } + /** A builder for [Body]. */ + class Builder internal constructor() { - /** Alias for calling [addScore] with `Score.ofInlinePrompt(inlinePrompt)`. */ - fun addScore(inlinePrompt: Score.InlinePrompt) = apply { body.addScore(inlinePrompt) } + private var data: JsonField? = null + private var projectId: JsonField? = null + private var scores: JsonField>? = null + private var task: JsonField? = null + private var baseExperimentId: JsonField = JsonMissing.of() + private var baseExperimentName: JsonField = JsonMissing.of() + private var experimentName: JsonField = JsonMissing.of() + private var gitMetadataSettings: JsonField = JsonMissing.of() + private var isPublic: JsonField = JsonMissing.of() + private var maxConcurrency: JsonField = JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var parent: JsonField = JsonMissing.of() + private var repoInfo: JsonField = JsonMissing.of() + private var stream: JsonField = JsonMissing.of() + private var timeout: JsonField = JsonMissing.of() + private var trialCount: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() - /** The function to evaluate */ - fun task(task: Task) = apply { body.task(task) } + @JvmSynthetic + internal fun from(body: Body) = apply { + data = body.data + projectId = body.projectId + scores = body.scores.map { it.toMutableList() } + task = body.task + baseExperimentId = body.baseExperimentId + baseExperimentName = body.baseExperimentName + experimentName = body.experimentName + gitMetadataSettings = body.gitMetadataSettings + isPublic = body.isPublic + maxConcurrency = body.maxConcurrency + metadata = body.metadata + parent = body.parent + repoInfo = body.repoInfo + stream = body.stream + timeout = body.timeout + trialCount = body.trialCount + additionalProperties = body.additionalProperties.toMutableMap() + } - /** - * Sets [Builder.task] to an arbitrary JSON value. - * - * You should usually call [Builder.task] with a well-typed [Task] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun task(task: JsonField) = apply { body.task(task) } + /** The dataset to use */ + fun data(data: Data) = data(JsonField.of(data)) - /** Alias for calling [task] with `Task.ofFunctionId(functionId)`. */ - fun task(functionId: Task.FunctionId) = apply { body.task(functionId) } + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed [Data] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun data(data: JsonField) = apply { this.data = data } - /** Alias for calling [task] with `Task.ofProjectSlug(projectSlug)`. */ - fun task(projectSlug: Task.ProjectSlug) = apply { body.task(projectSlug) } + /** Alias for calling [data] with `Data.ofDatasetId(datasetId)`. */ + fun data(datasetId: Data.DatasetId) = data(Data.ofDatasetId(datasetId)) - /** Alias for calling [task] with `Task.ofGlobalFunction(globalFunction)`. */ - fun task(globalFunction: Task.GlobalFunction) = apply { body.task(globalFunction) } + /** Alias for calling [data] with `Data.ofProjectDatasetName(projectDatasetName)`. */ + fun data(projectDatasetName: Data.ProjectDatasetName) = + data(Data.ofProjectDatasetName(projectDatasetName)) - /** Alias for calling [task] with `Task.ofPromptSessionId(promptSessionId)`. */ - fun task(promptSessionId: Task.PromptSessionId) = apply { body.task(promptSessionId) } + /** Alias for calling [data] with `Data.ofDatasetRows(datasetRows)`. */ + fun data(datasetRows: Data.DatasetRows) = data(Data.ofDatasetRows(datasetRows)) - /** Alias for calling [task] with `Task.ofInlineCode(inlineCode)`. */ - fun task(inlineCode: Task.InlineCode) = apply { body.task(inlineCode) } + /** Unique identifier for the project to run the eval in */ + fun projectId(projectId: String) = projectId(JsonField.of(projectId)) - /** Alias for calling [task] with `Task.ofInlinePrompt(inlinePrompt)`. */ - fun task(inlinePrompt: Task.InlinePrompt) = apply { body.task(inlinePrompt) } + /** + * Sets [Builder.projectId] to an arbitrary JSON value. + * + * You should usually call [Builder.projectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun projectId(projectId: JsonField) = apply { this.projectId = projectId } - /** - * An optional experiment id to use as a base. If specified, the new experiment will be - * summarized and compared to this experiment. - */ - fun baseExperimentId(baseExperimentId: String?) = apply { - body.baseExperimentId(baseExperimentId) - } + /** The functions to score the eval on */ + fun scores(scores: List) = scores(JsonField.of(scores)) - /** Alias for calling [Builder.baseExperimentId] with `baseExperimentId.orElse(null)`. */ - fun baseExperimentId(baseExperimentId: Optional) = - baseExperimentId(baseExperimentId.getOrNull()) + /** + * Sets [Builder.scores] to an arbitrary JSON value. + * + * You should usually call [Builder.scores] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun scores(scores: JsonField>) = apply { + this.scores = scores.map { it.toMutableList() } + } + + /** + * Adds a single [Score] to [scores]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addScore(score: Score) = apply { + scores = + (scores ?: JsonField.of(mutableListOf())).also { + checkKnown("scores", it).add(score) + } + } + + /** Alias for calling [addScore] with `Score.ofFunctionId(functionId)`. */ + fun addScore(functionId: Score.FunctionId) = addScore(Score.ofFunctionId(functionId)) - /** - * Sets [Builder.baseExperimentId] to an arbitrary JSON value. - * - * You should usually call [Builder.baseExperimentId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun baseExperimentId(baseExperimentId: JsonField) = apply { - body.baseExperimentId(baseExperimentId) - } + /** Alias for calling [addScore] with `Score.ofProjectSlug(projectSlug)`. */ + fun addScore(projectSlug: Score.ProjectSlug) = + addScore(Score.ofProjectSlug(projectSlug)) - /** - * An optional experiment name to use as a base. If specified, the new experiment will be - * summarized and compared to this experiment. - */ - fun baseExperimentName(baseExperimentName: String?) = apply { - body.baseExperimentName(baseExperimentName) - } + /** Alias for calling [addScore] with `Score.ofGlobalFunction(globalFunction)`. */ + fun addScore(globalFunction: Score.GlobalFunction) = + addScore(Score.ofGlobalFunction(globalFunction)) - /** - * Alias for calling [Builder.baseExperimentName] with `baseExperimentName.orElse(null)`. - */ - fun baseExperimentName(baseExperimentName: Optional) = - baseExperimentName(baseExperimentName.getOrNull()) + /** Alias for calling [addScore] with `Score.ofPromptSessionId(promptSessionId)`. */ + fun addScore(promptSessionId: Score.PromptSessionId) = + addScore(Score.ofPromptSessionId(promptSessionId)) - /** - * Sets [Builder.baseExperimentName] to an arbitrary JSON value. - * - * You should usually call [Builder.baseExperimentName] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun baseExperimentName(baseExperimentName: JsonField) = apply { - body.baseExperimentName(baseExperimentName) - } + /** Alias for calling [addScore] with `Score.ofInlineCode(inlineCode)`. */ + fun addScore(inlineCode: Score.InlineCode) = addScore(Score.ofInlineCode(inlineCode)) - /** - * An optional name for the experiment created by this eval. If it conflicts with an - * existing experiment, it will be suffixed with a unique identifier. - */ - fun experimentName(experimentName: String) = apply { body.experimentName(experimentName) } + /** Alias for calling [addScore] with `Score.ofInlinePrompt(inlinePrompt)`. */ + fun addScore(inlinePrompt: Score.InlinePrompt) = + addScore(Score.ofInlinePrompt(inlinePrompt)) - /** - * Sets [Builder.experimentName] to an arbitrary JSON value. - * - * You should usually call [Builder.experimentName] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun experimentName(experimentName: JsonField) = apply { - body.experimentName(experimentName) - } + /** The function to evaluate */ + fun task(task: Task) = task(JsonField.of(task)) - /** - * Optional settings for collecting git metadata. By default, will collect all git metadata - * fields allowed in org-level settings. - */ - fun gitMetadataSettings(gitMetadataSettings: GitMetadataSettings?) = apply { - body.gitMetadataSettings(gitMetadataSettings) - } + /** + * Sets [Builder.task] to an arbitrary JSON value. + * + * You should usually call [Builder.task] with a well-typed [Task] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun task(task: JsonField) = apply { this.task = task } - /** - * Alias for calling [Builder.gitMetadataSettings] with `gitMetadataSettings.orElse(null)`. - */ - fun gitMetadataSettings(gitMetadataSettings: Optional) = - gitMetadataSettings(gitMetadataSettings.getOrNull()) + /** Alias for calling [task] with `Task.ofFunctionId(functionId)`. */ + fun task(functionId: Task.FunctionId) = task(Task.ofFunctionId(functionId)) - /** - * Sets [Builder.gitMetadataSettings] to an arbitrary JSON value. - * - * You should usually call [Builder.gitMetadataSettings] with a well-typed - * [GitMetadataSettings] value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun gitMetadataSettings(gitMetadataSettings: JsonField) = apply { - body.gitMetadataSettings(gitMetadataSettings) - } + /** Alias for calling [task] with `Task.ofProjectSlug(projectSlug)`. */ + fun task(projectSlug: Task.ProjectSlug) = task(Task.ofProjectSlug(projectSlug)) - /** Whether the experiment should be public. Defaults to false. */ - fun isPublic(isPublic: Boolean?) = apply { body.isPublic(isPublic) } + /** Alias for calling [task] with `Task.ofGlobalFunction(globalFunction)`. */ + fun task(globalFunction: Task.GlobalFunction) = + task(Task.ofGlobalFunction(globalFunction)) - /** - * Alias for [Builder.isPublic]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun isPublic(isPublic: Boolean) = isPublic(isPublic as Boolean?) + /** Alias for calling [task] with `Task.ofPromptSessionId(promptSessionId)`. */ + fun task(promptSessionId: Task.PromptSessionId) = + task(Task.ofPromptSessionId(promptSessionId)) - /** Alias for calling [Builder.isPublic] with `isPublic.orElse(null)`. */ - fun isPublic(isPublic: Optional) = isPublic(isPublic.getOrNull()) + /** Alias for calling [task] with `Task.ofInlineCode(inlineCode)`. */ + fun task(inlineCode: Task.InlineCode) = task(Task.ofInlineCode(inlineCode)) - /** - * Sets [Builder.isPublic] to an arbitrary JSON value. - * - * You should usually call [Builder.isPublic] with a well-typed [Boolean] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun isPublic(isPublic: JsonField) = apply { body.isPublic(isPublic) } + /** Alias for calling [task] with `Task.ofInlinePrompt(inlinePrompt)`. */ + fun task(inlinePrompt: Task.InlinePrompt) = task(Task.ofInlinePrompt(inlinePrompt)) - /** - * The maximum number of tasks/scorers that will be run concurrently. Defaults to undefined, - * in which case there is no max concurrency. - */ - fun maxConcurrency(maxConcurrency: Double?) = apply { body.maxConcurrency(maxConcurrency) } + /** + * An optional experiment id to use as a base. If specified, the new experiment will be + * summarized and compared to this experiment. + */ + fun baseExperimentId(baseExperimentId: String?) = + baseExperimentId(JsonField.ofNullable(baseExperimentId)) - /** - * Alias for [Builder.maxConcurrency]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun maxConcurrency(maxConcurrency: Double) = maxConcurrency(maxConcurrency as Double?) + /** + * Alias for calling [Builder.baseExperimentId] with `baseExperimentId.orElse(null)`. + */ + fun baseExperimentId(baseExperimentId: Optional) = + baseExperimentId(baseExperimentId.getOrNull()) - /** Alias for calling [Builder.maxConcurrency] with `maxConcurrency.orElse(null)`. */ - fun maxConcurrency(maxConcurrency: Optional) = - maxConcurrency(maxConcurrency.getOrNull()) + /** + * Sets [Builder.baseExperimentId] to an arbitrary JSON value. + * + * You should usually call [Builder.baseExperimentId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun baseExperimentId(baseExperimentId: JsonField) = apply { + this.baseExperimentId = baseExperimentId + } - /** - * Sets [Builder.maxConcurrency] to an arbitrary JSON value. - * - * You should usually call [Builder.maxConcurrency] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun maxConcurrency(maxConcurrency: JsonField) = apply { - body.maxConcurrency(maxConcurrency) - } + /** + * An optional experiment name to use as a base. If specified, the new experiment will + * be summarized and compared to this experiment. + */ + fun baseExperimentName(baseExperimentName: String?) = + baseExperimentName(JsonField.ofNullable(baseExperimentName)) - /** - * Optional experiment-level metadata to store about the evaluation. You can later use this - * to slice & dice across experiments. - */ - fun metadata(metadata: Metadata) = apply { body.metadata(metadata) } + /** + * Alias for calling [Builder.baseExperimentName] with + * `baseExperimentName.orElse(null)`. + */ + fun baseExperimentName(baseExperimentName: Optional) = + baseExperimentName(baseExperimentName.getOrNull()) - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun metadata(metadata: JsonField) = apply { body.metadata(metadata) } + /** + * Sets [Builder.baseExperimentName] to an arbitrary JSON value. + * + * You should usually call [Builder.baseExperimentName] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun baseExperimentName(baseExperimentName: JsonField) = apply { + this.baseExperimentName = baseExperimentName + } - /** Options for tracing the evaluation */ - fun parent(parent: Parent) = apply { body.parent(parent) } + /** + * An optional name for the experiment created by this eval. If it conflicts with an + * existing experiment, it will be suffixed with a unique identifier. + */ + fun experimentName(experimentName: String) = + experimentName(JsonField.of(experimentName)) - /** - * Sets [Builder.parent] to an arbitrary JSON value. - * - * You should usually call [Builder.parent] with a well-typed [Parent] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun parent(parent: JsonField) = apply { body.parent(parent) } + /** + * Sets [Builder.experimentName] to an arbitrary JSON value. + * + * You should usually call [Builder.experimentName] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun experimentName(experimentName: JsonField) = apply { + this.experimentName = experimentName + } - /** Alias for calling [parent] with `Parent.ofSpanParentStruct(spanParentStruct)`. */ - fun parent(spanParentStruct: Parent.SpanParentStruct) = apply { - body.parent(spanParentStruct) - } + /** + * Optional settings for collecting git metadata. By default, will collect all git + * metadata fields allowed in org-level settings. + */ + fun gitMetadataSettings(gitMetadataSettings: GitMetadataSettings?) = + gitMetadataSettings(JsonField.ofNullable(gitMetadataSettings)) - /** Alias for calling [parent] with `Parent.ofString(string)`. */ - fun parent(string: String) = apply { body.parent(string) } + /** + * Alias for calling [Builder.gitMetadataSettings] with + * `gitMetadataSettings.orElse(null)`. + */ + fun gitMetadataSettings(gitMetadataSettings: Optional) = + gitMetadataSettings(gitMetadataSettings.getOrNull()) - /** Metadata about the state of the repo when the experiment was created */ - fun repoInfo(repoInfo: RepoInfo?) = apply { body.repoInfo(repoInfo) } + /** + * Sets [Builder.gitMetadataSettings] to an arbitrary JSON value. + * + * You should usually call [Builder.gitMetadataSettings] with a well-typed + * [GitMetadataSettings] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun gitMetadataSettings(gitMetadataSettings: JsonField) = apply { + this.gitMetadataSettings = gitMetadataSettings + } - /** Alias for calling [Builder.repoInfo] with `repoInfo.orElse(null)`. */ - fun repoInfo(repoInfo: Optional) = repoInfo(repoInfo.getOrNull()) + /** Whether the experiment should be public. Defaults to false. */ + fun isPublic(isPublic: Boolean?) = isPublic(JsonField.ofNullable(isPublic)) - /** - * Sets [Builder.repoInfo] to an arbitrary JSON value. - * - * You should usually call [Builder.repoInfo] with a well-typed [RepoInfo] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun repoInfo(repoInfo: JsonField) = apply { body.repoInfo(repoInfo) } + /** + * Alias for [Builder.isPublic]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun isPublic(isPublic: Boolean) = isPublic(isPublic as Boolean?) - /** - * Whether to stream the results of the eval. If true, the request will return two events: - * one to indicate the experiment has started, and another upon completion. If false, the - * request will return the evaluation's summary upon completion. - */ - fun stream(stream: Boolean) = apply { body.stream(stream) } + /** Alias for calling [Builder.isPublic] with `isPublic.orElse(null)`. */ + fun isPublic(isPublic: Optional) = isPublic(isPublic.getOrNull()) - /** - * Sets [Builder.stream] to an arbitrary JSON value. - * - * You should usually call [Builder.stream] with a well-typed [Boolean] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun stream(stream: JsonField) = apply { body.stream(stream) } + /** + * Sets [Builder.isPublic] to an arbitrary JSON value. + * + * You should usually call [Builder.isPublic] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun isPublic(isPublic: JsonField) = apply { this.isPublic = isPublic } - /** - * The maximum duration, in milliseconds, to run the evaluation. Defaults to undefined, in - * which case there is no timeout. - */ - fun timeout(timeout: Double?) = apply { body.timeout(timeout) } + /** + * The maximum number of tasks/scorers that will be run concurrently. Defaults to + * undefined, in which case there is no max concurrency. + */ + fun maxConcurrency(maxConcurrency: Double?) = + maxConcurrency(JsonField.ofNullable(maxConcurrency)) - /** - * Alias for [Builder.timeout]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun timeout(timeout: Double) = timeout(timeout as Double?) + /** + * Alias for [Builder.maxConcurrency]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun maxConcurrency(maxConcurrency: Double) = maxConcurrency(maxConcurrency as Double?) - /** Alias for calling [Builder.timeout] with `timeout.orElse(null)`. */ - fun timeout(timeout: Optional) = timeout(timeout.getOrNull()) + /** Alias for calling [Builder.maxConcurrency] with `maxConcurrency.orElse(null)`. */ + fun maxConcurrency(maxConcurrency: Optional) = + maxConcurrency(maxConcurrency.getOrNull()) - /** - * Sets [Builder.timeout] to an arbitrary JSON value. - * - * You should usually call [Builder.timeout] with a well-typed [Double] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun timeout(timeout: JsonField) = apply { body.timeout(timeout) } + /** + * Sets [Builder.maxConcurrency] to an arbitrary JSON value. + * + * You should usually call [Builder.maxConcurrency] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun maxConcurrency(maxConcurrency: JsonField) = apply { + this.maxConcurrency = maxConcurrency + } - /** - * The number of times to run the evaluator per input. This is useful for evaluating - * applications that have non-deterministic behavior and gives you both a stronger aggregate - * measure and a sense of the variance in the results. - */ - fun trialCount(trialCount: Double?) = apply { body.trialCount(trialCount) } + /** + * Optional experiment-level metadata to store about the evaluation. You can later use + * this to slice & dice across experiments. + */ + fun metadata(metadata: Metadata) = metadata(JsonField.of(metadata)) - /** - * Alias for [Builder.trialCount]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun trialCount(trialCount: Double) = trialCount(trialCount as Double?) + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - /** Alias for calling [Builder.trialCount] with `trialCount.orElse(null)`. */ - fun trialCount(trialCount: Optional) = trialCount(trialCount.getOrNull()) + /** Options for tracing the evaluation */ + fun parent(parent: Parent) = parent(JsonField.of(parent)) - /** - * Sets [Builder.trialCount] to an arbitrary JSON value. - * - * You should usually call [Builder.trialCount] with a well-typed [Double] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun trialCount(trialCount: JsonField) = apply { body.trialCount(trialCount) } + /** + * Sets [Builder.parent] to an arbitrary JSON value. + * + * You should usually call [Builder.parent] with a well-typed [Parent] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun parent(parent: JsonField) = apply { this.parent = parent } - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) - } + /** Alias for calling [parent] with `Parent.ofSpanParentStruct(spanParentStruct)`. */ + fun parent(spanParentStruct: Parent.SpanParentStruct) = + parent(Parent.ofSpanParentStruct(spanParentStruct)) - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } + /** Alias for calling [parent] with `Parent.ofString(string)`. */ + fun parent(string: String) = parent(Parent.ofString(string)) - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) - } + /** Metadata about the state of the repo when the experiment was created */ + fun repoInfo(repoInfo: RepoInfo?) = repoInfo(JsonField.ofNullable(repoInfo)) - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + /** Alias for calling [Builder.repoInfo] with `repoInfo.orElse(null)`. */ + fun repoInfo(repoInfo: Optional) = repoInfo(repoInfo.getOrNull()) - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } + /** + * Sets [Builder.repoInfo] to an arbitrary JSON value. + * + * You should usually call [Builder.repoInfo] with a well-typed [RepoInfo] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun repoInfo(repoInfo: JsonField) = apply { this.repoInfo = repoInfo } - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * Whether to stream the results of the eval. If true, the request will return two + * events: one to indicate the experiment has started, and another upon completion. If + * false, the request will return the evaluation's summary upon completion. + */ + fun stream(stream: Boolean) = stream(JsonField.of(stream)) - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * Sets [Builder.stream] to an arbitrary JSON value. + * + * You should usually call [Builder.stream] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun stream(stream: JsonField) = apply { this.stream = stream } - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } + /** + * The maximum duration, in milliseconds, to run the evaluation. Defaults to undefined, + * in which case there is no timeout. + */ + fun timeout(timeout: Double?) = timeout(JsonField.ofNullable(timeout)) - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } + /** + * Alias for [Builder.timeout]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun timeout(timeout: Double) = timeout(timeout as Double?) - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** Alias for calling [Builder.timeout] with `timeout.orElse(null)`. */ + fun timeout(timeout: Optional) = timeout(timeout.getOrNull()) - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** + * Sets [Builder.timeout] to an arbitrary JSON value. + * + * You should usually call [Builder.timeout] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun timeout(timeout: JsonField) = apply { this.timeout = timeout } - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } + /** + * The number of times to run the evaluator per input. This is useful for evaluating + * applications that have non-deterministic behavior and gives you both a stronger + * aggregate measure and a sense of the variance in the results. + */ + fun trialCount(trialCount: Double?) = trialCount(JsonField.ofNullable(trialCount)) - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } + /** + * Alias for [Builder.trialCount]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun trialCount(trialCount: Double) = trialCount(trialCount as Double?) - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** Alias for calling [Builder.trialCount] with `trialCount.orElse(null)`. */ + fun trialCount(trialCount: Optional) = trialCount(trialCount.getOrNull()) - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** + * Sets [Builder.trialCount] to an arbitrary JSON value. + * + * You should usually call [Builder.trialCount] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun trialCount(trialCount: JsonField) = apply { this.trialCount = trialCount } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .projectId() + * .scores() + * .task() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("data", data), + checkRequired("projectId", projectId), + checkRequired("scores", scores).map { it.toImmutable() }, + checkRequired("task", task), + baseExperimentId, + baseExperimentName, + experimentName, + gitMetadataSettings, + isPublic, + maxConcurrency, + metadata, + parent, + repoInfo, + stream, + timeout, + trialCount, + additionalProperties.toMutableMap(), + ) } - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } + private var validated: Boolean = false - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + fun validate(): Body = apply { + if (validated) { + return@apply } - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) + data().validate() + projectId() + scores().forEach { it.validate() } + task().validate() + baseExperimentId() + baseExperimentName() + experimentName() + gitMetadataSettings().ifPresent { it.validate() } + isPublic() + maxConcurrency() + metadata().ifPresent { it.validate() } + parent().ifPresent { it.validate() } + repoInfo().ifPresent { it.validate() } + stream() + timeout() + trialCount() + validated = true } - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + return /* spotless:off */ other is Body && data == other.data && projectId == other.projectId && scores == other.scores && task == other.task && baseExperimentId == other.baseExperimentId && baseExperimentName == other.baseExperimentName && experimentName == other.experimentName && gitMetadataSettings == other.gitMetadataSettings && isPublic == other.isPublic && maxConcurrency == other.maxConcurrency && metadata == other.metadata && parent == other.parent && repoInfo == other.repoInfo && stream == other.stream && timeout == other.timeout && trialCount == other.trialCount && additionalProperties == other.additionalProperties /* spotless:on */ } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) - } - - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, projectId, scores, task, baseExperimentId, baseExperimentName, experimentName, gitMetadataSettings, isPublic, maxConcurrency, metadata, parent, repoInfo, stream, timeout, trialCount, additionalProperties) } + /* spotless:on */ - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) - } + override fun hashCode(): Int = hashCode - /** - * Returns an immutable instance of [EvalCreateParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .data() - * .projectId() - * .scores() - * .task() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): EvalCreateParams = - EvalCreateParams(body.build(), additionalHeaders.build(), additionalQueryParams.build()) + override fun toString() = + "Body{data=$data, projectId=$projectId, scores=$scores, task=$task, baseExperimentId=$baseExperimentId, baseExperimentName=$baseExperimentName, experimentName=$experimentName, gitMetadataSettings=$gitMetadataSettings, isPublic=$isPublic, maxConcurrency=$maxConcurrency, metadata=$metadata, parent=$parent, repoInfo=$repoInfo, stream=$stream, timeout=$timeout, trialCount=$trialCount, additionalProperties=$additionalProperties}" } /** The dataset to use */ @@ -1875,20 +1908,23 @@ private constructor( } /** Dataset id */ - @NoAutoDetect class DatasetId - @JsonCreator private constructor( - @JsonProperty("dataset_id") - @ExcludeMissing - private val datasetId: JsonField = JsonMissing.of(), - @JsonProperty("_internal_btql") - @ExcludeMissing - private val _internalBtql: JsonField<_InternalBtql> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val datasetId: JsonField, + private val _internalBtql: JsonField<_InternalBtql>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("dataset_id") + @ExcludeMissing + datasetId: JsonField = JsonMissing.of(), + @JsonProperty("_internal_btql") + @ExcludeMissing + _internalBtql: JsonField<_InternalBtql> = JsonMissing.of(), + ) : this(datasetId, _internalBtql, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -1923,21 +1959,15 @@ private constructor( @ExcludeMissing fun __internalBtql(): JsonField<_InternalBtql> = _internalBtql + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): DatasetId = apply { - if (validated) { - return@apply - } - - datasetId() - _internalBtql().ifPresent { it.validate() } - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -2035,32 +2065,37 @@ private constructor( DatasetId( checkRequired("datasetId", datasetId), _internalBtql, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } - @NoAutoDetect - class _InternalBtql - @JsonCreator - private constructor( - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private var validated: Boolean = false - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun validate(): DatasetId = apply { + if (validated) { + return@apply + } - private var validated: Boolean = false + datasetId() + _internalBtql().ifPresent { it.validate() } + validated = true + } - fun validate(): _InternalBtql = apply { - if (validated) { - return@apply - } + class _InternalBtql + private constructor(private val additionalProperties: MutableMap) { - validated = true + @JsonCreator private constructor() : this(mutableMapOf()) + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + fun toBuilder() = Builder().from(this) companion object { @@ -2108,7 +2143,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): _InternalBtql = _InternalBtql(additionalProperties.toImmutable()) + fun build(): _InternalBtql = _InternalBtql(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): _InternalBtql = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { @@ -2148,23 +2193,27 @@ private constructor( } /** Project and dataset name */ - @NoAutoDetect class ProjectDatasetName - @JsonCreator private constructor( - @JsonProperty("dataset_name") - @ExcludeMissing - private val datasetName: JsonField = JsonMissing.of(), - @JsonProperty("project_name") - @ExcludeMissing - private val projectName: JsonField = JsonMissing.of(), - @JsonProperty("_internal_btql") - @ExcludeMissing - private val _internalBtql: JsonField<_InternalBtql> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val datasetName: JsonField, + private val projectName: JsonField, + private val _internalBtql: JsonField<_InternalBtql>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("dataset_name") + @ExcludeMissing + datasetName: JsonField = JsonMissing.of(), + @JsonProperty("project_name") + @ExcludeMissing + projectName: JsonField = JsonMissing.of(), + @JsonProperty("_internal_btql") + @ExcludeMissing + _internalBtql: JsonField<_InternalBtql> = JsonMissing.of(), + ) : this(datasetName, projectName, _internalBtql, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -2216,22 +2265,15 @@ private constructor( @ExcludeMissing fun __internalBtql(): JsonField<_InternalBtql> = _internalBtql + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): ProjectDatasetName = apply { - if (validated) { - return@apply - } - - datasetName() - projectName() - _internalBtql().ifPresent { it.validate() } - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -2349,32 +2391,38 @@ private constructor( checkRequired("datasetName", datasetName), checkRequired("projectName", projectName), _internalBtql, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } - @NoAutoDetect - class _InternalBtql - @JsonCreator - private constructor( - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private var validated: Boolean = false - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun validate(): ProjectDatasetName = apply { + if (validated) { + return@apply + } - private var validated: Boolean = false + datasetName() + projectName() + _internalBtql().ifPresent { it.validate() } + validated = true + } - fun validate(): _InternalBtql = apply { - if (validated) { - return@apply - } + class _InternalBtql + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) - validated = true + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + fun toBuilder() = Builder().from(this) companion object { @@ -2422,7 +2470,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): _InternalBtql = _InternalBtql(additionalProperties.toImmutable()) + fun build(): _InternalBtql = _InternalBtql(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): _InternalBtql = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { @@ -2462,17 +2520,19 @@ private constructor( } /** Dataset rows */ - @NoAutoDetect class DatasetRows - @JsonCreator private constructor( - @JsonProperty("data") - @ExcludeMissing - private val data: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val data: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of() + ) : this(data, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -2487,20 +2547,15 @@ private constructor( */ @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): DatasetRows = apply { - if (validated) { - return@apply - } - - data() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -2591,10 +2646,21 @@ private constructor( fun build(): DatasetRows = DatasetRows( checkRequired("data", data).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): DatasetRows = apply { + if (validated) { + return@apply + } + + data() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2867,20 +2933,23 @@ private constructor( } /** Function id */ - @NoAutoDetect class FunctionId - @JsonCreator private constructor( - @JsonProperty("function_id") - @ExcludeMissing - private val functionId: JsonField = JsonMissing.of(), - @JsonProperty("version") - @ExcludeMissing - private val version: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val functionId: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("function_id") + @ExcludeMissing + functionId: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + version: JsonField = JsonMissing.of(), + ) : this(functionId, version, mutableMapOf()) + /** * The ID of the function * @@ -2915,21 +2984,15 @@ private constructor( */ @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): FunctionId = apply { - if (validated) { - return@apply - } - - functionId() - version() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -3024,10 +3087,22 @@ private constructor( FunctionId( checkRequired("functionId", functionId), version, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): FunctionId = apply { + if (validated) { + return@apply + } + + functionId() + version() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3047,23 +3122,25 @@ private constructor( } /** Project name and slug */ - @NoAutoDetect class ProjectSlug - @JsonCreator private constructor( - @JsonProperty("project_name") - @ExcludeMissing - private val projectName: JsonField = JsonMissing.of(), - @JsonProperty("slug") - @ExcludeMissing - private val slug: JsonField = JsonMissing.of(), - @JsonProperty("version") - @ExcludeMissing - private val version: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val projectName: JsonField, + private val slug: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("project_name") + @ExcludeMissing + projectName: JsonField = JsonMissing.of(), + @JsonProperty("slug") @ExcludeMissing slug: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + version: JsonField = JsonMissing.of(), + ) : this(projectName, slug, version, mutableMapOf()) + /** * The name of the project containing the function * @@ -3114,22 +3191,15 @@ private constructor( */ @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): ProjectSlug = apply { - if (validated) { - return@apply - } - - projectName() - slug() - version() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -3241,10 +3311,23 @@ private constructor( checkRequired("projectName", projectName), checkRequired("slug", slug), version, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): ProjectSlug = apply { + if (validated) { + return@apply + } + + projectName() + slug() + version() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3264,17 +3347,19 @@ private constructor( } /** Global function name */ - @NoAutoDetect class GlobalFunction - @JsonCreator private constructor( - @JsonProperty("global_function") - @ExcludeMissing - private val globalFunction: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val globalFunction: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("global_function") + @ExcludeMissing + globalFunction: JsonField = JsonMissing.of() + ) : this(globalFunction, mutableMapOf()) + /** * The name of the global function. Currently, the global namespace includes the * functions in autoevals @@ -3295,20 +3380,15 @@ private constructor( @ExcludeMissing fun _globalFunction(): JsonField = globalFunction + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): GlobalFunction = apply { - if (validated) { - return@apply - } - - globalFunction() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -3392,10 +3472,21 @@ private constructor( fun build(): GlobalFunction = GlobalFunction( checkRequired("globalFunction", globalFunction), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): GlobalFunction = apply { + if (validated) { + return@apply + } + + globalFunction() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3415,23 +3506,27 @@ private constructor( } /** Prompt session id */ - @NoAutoDetect class PromptSessionId - @JsonCreator private constructor( - @JsonProperty("prompt_session_function_id") - @ExcludeMissing - private val promptSessionFunctionId: JsonField = JsonMissing.of(), - @JsonProperty("prompt_session_id") - @ExcludeMissing - private val promptSessionId: JsonField = JsonMissing.of(), - @JsonProperty("version") - @ExcludeMissing - private val version: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val promptSessionFunctionId: JsonField, + private val promptSessionId: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("prompt_session_function_id") + @ExcludeMissing + promptSessionFunctionId: JsonField = JsonMissing.of(), + @JsonProperty("prompt_session_id") + @ExcludeMissing + promptSessionId: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + version: JsonField = JsonMissing.of(), + ) : this(promptSessionFunctionId, promptSessionId, version, mutableMapOf()) + /** * The ID of the function in the prompt session * @@ -3486,22 +3581,15 @@ private constructor( */ @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): PromptSessionId = apply { - if (validated) { - return@apply - } - - promptSessionFunctionId() - promptSessionId() - version() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -3617,10 +3705,23 @@ private constructor( checkRequired("promptSessionFunctionId", promptSessionFunctionId), checkRequired("promptSessionId", promptSessionId), version, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): PromptSessionId = apply { + if (validated) { + return@apply + } + + promptSessionFunctionId() + promptSessionId() + version() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3640,23 +3741,23 @@ private constructor( } /** Inline code function */ - @NoAutoDetect class InlineCode - @JsonCreator private constructor( - @JsonProperty("code") - @ExcludeMissing - private val code: JsonField = JsonMissing.of(), - @JsonProperty("inline_context") - @ExcludeMissing - private val inlineContext: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val code: JsonField, + private val inlineContext: JsonField, + private val name: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("code") @ExcludeMissing code: JsonField = JsonMissing.of(), + @JsonProperty("inline_context") + @ExcludeMissing + inlineContext: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + ) : this(code, inlineContext, name, mutableMapOf()) + /** * The inline code to execute * @@ -3705,22 +3806,15 @@ private constructor( */ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): InlineCode = apply { - if (validated) { - return@apply - } - - code() - inlineContext().validate() - name() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -3835,24 +3929,40 @@ private constructor( checkRequired("code", code), checkRequired("inlineContext", inlineContext), name, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } - @NoAutoDetect - class InlineContext - @JsonCreator - private constructor( - @JsonProperty("runtime") - @ExcludeMissing - private val runtime: JsonField = JsonMissing.of(), - @JsonProperty("version") - @ExcludeMissing - private val version: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private var validated: Boolean = false + + fun validate(): InlineCode = apply { + if (validated) { + return@apply + } + + code() + inlineContext().validate() + name() + validated = true + } + + class InlineContext + private constructor( + private val runtime: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("runtime") + @ExcludeMissing + runtime: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + version: JsonField = JsonMissing.of(), + ) : this(runtime, version, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type * or is unexpectedly missing or null (e.g. if the server responded with an @@ -3885,21 +3995,15 @@ private constructor( */ @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): InlineContext = apply { - if (validated) { - return@apply - } - - runtime() - version() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -3992,10 +4096,22 @@ private constructor( InlineContext( checkRequired("runtime", runtime), checkRequired("version", version), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): InlineContext = apply { + if (validated) { + return@apply + } + + runtime() + version() + validated = true + } + class Runtime @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -4139,20 +4255,21 @@ private constructor( } /** Inline prompt definition */ - @NoAutoDetect class InlinePrompt - @JsonCreator private constructor( - @JsonProperty("inline_prompt") - @ExcludeMissing - private val inlinePrompt: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val inlinePrompt: JsonField, + private val name: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("inline_prompt") + @ExcludeMissing + inlinePrompt: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + ) : this(inlinePrompt, name, mutableMapOf()) + /** * The prompt, model, and its parameters * @@ -4187,21 +4304,15 @@ private constructor( */ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): InlinePrompt = apply { - if (validated) { - return@apply - } - - inlinePrompt().ifPresent { it.validate() } - name() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -4304,10 +4415,22 @@ private constructor( InlinePrompt( checkRequired("inlinePrompt", inlinePrompt), name, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): InlinePrompt = apply { + if (validated) { + return@apply + } + + inlinePrompt().ifPresent { it.validate() } + name() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -4578,20 +4701,23 @@ private constructor( } /** Function id */ - @NoAutoDetect class FunctionId - @JsonCreator private constructor( - @JsonProperty("function_id") - @ExcludeMissing - private val functionId: JsonField = JsonMissing.of(), - @JsonProperty("version") - @ExcludeMissing - private val version: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val functionId: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("function_id") + @ExcludeMissing + functionId: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + version: JsonField = JsonMissing.of(), + ) : this(functionId, version, mutableMapOf()) + /** * The ID of the function * @@ -4626,21 +4752,15 @@ private constructor( */ @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): FunctionId = apply { - if (validated) { - return@apply - } - - functionId() - version() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -4735,10 +4855,22 @@ private constructor( FunctionId( checkRequired("functionId", functionId), version, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): FunctionId = apply { + if (validated) { + return@apply + } + + functionId() + version() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -4758,23 +4890,25 @@ private constructor( } /** Project name and slug */ - @NoAutoDetect class ProjectSlug - @JsonCreator private constructor( - @JsonProperty("project_name") - @ExcludeMissing - private val projectName: JsonField = JsonMissing.of(), - @JsonProperty("slug") - @ExcludeMissing - private val slug: JsonField = JsonMissing.of(), - @JsonProperty("version") - @ExcludeMissing - private val version: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val projectName: JsonField, + private val slug: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("project_name") + @ExcludeMissing + projectName: JsonField = JsonMissing.of(), + @JsonProperty("slug") @ExcludeMissing slug: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + version: JsonField = JsonMissing.of(), + ) : this(projectName, slug, version, mutableMapOf()) + /** * The name of the project containing the function * @@ -4825,22 +4959,15 @@ private constructor( */ @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): ProjectSlug = apply { - if (validated) { - return@apply - } - - projectName() - slug() - version() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -4952,10 +5079,23 @@ private constructor( checkRequired("projectName", projectName), checkRequired("slug", slug), version, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): ProjectSlug = apply { + if (validated) { + return@apply + } + + projectName() + slug() + version() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -4975,17 +5115,19 @@ private constructor( } /** Global function name */ - @NoAutoDetect class GlobalFunction - @JsonCreator private constructor( - @JsonProperty("global_function") - @ExcludeMissing - private val globalFunction: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val globalFunction: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("global_function") + @ExcludeMissing + globalFunction: JsonField = JsonMissing.of() + ) : this(globalFunction, mutableMapOf()) + /** * The name of the global function. Currently, the global namespace includes the * functions in autoevals @@ -5006,20 +5148,15 @@ private constructor( @ExcludeMissing fun _globalFunction(): JsonField = globalFunction + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): GlobalFunction = apply { - if (validated) { - return@apply - } - - globalFunction() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -5103,10 +5240,21 @@ private constructor( fun build(): GlobalFunction = GlobalFunction( checkRequired("globalFunction", globalFunction), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): GlobalFunction = apply { + if (validated) { + return@apply + } + + globalFunction() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -5126,23 +5274,27 @@ private constructor( } /** Prompt session id */ - @NoAutoDetect class PromptSessionId - @JsonCreator private constructor( - @JsonProperty("prompt_session_function_id") - @ExcludeMissing - private val promptSessionFunctionId: JsonField = JsonMissing.of(), - @JsonProperty("prompt_session_id") - @ExcludeMissing - private val promptSessionId: JsonField = JsonMissing.of(), - @JsonProperty("version") - @ExcludeMissing - private val version: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val promptSessionFunctionId: JsonField, + private val promptSessionId: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("prompt_session_function_id") + @ExcludeMissing + promptSessionFunctionId: JsonField = JsonMissing.of(), + @JsonProperty("prompt_session_id") + @ExcludeMissing + promptSessionId: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + version: JsonField = JsonMissing.of(), + ) : this(promptSessionFunctionId, promptSessionId, version, mutableMapOf()) + /** * The ID of the function in the prompt session * @@ -5197,22 +5349,15 @@ private constructor( */ @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): PromptSessionId = apply { - if (validated) { - return@apply - } - - promptSessionFunctionId() - promptSessionId() - version() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -5328,10 +5473,23 @@ private constructor( checkRequired("promptSessionFunctionId", promptSessionFunctionId), checkRequired("promptSessionId", promptSessionId), version, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): PromptSessionId = apply { + if (validated) { + return@apply + } + + promptSessionFunctionId() + promptSessionId() + version() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -5351,23 +5509,23 @@ private constructor( } /** Inline code function */ - @NoAutoDetect class InlineCode - @JsonCreator private constructor( - @JsonProperty("code") - @ExcludeMissing - private val code: JsonField = JsonMissing.of(), - @JsonProperty("inline_context") - @ExcludeMissing - private val inlineContext: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val code: JsonField, + private val inlineContext: JsonField, + private val name: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("code") @ExcludeMissing code: JsonField = JsonMissing.of(), + @JsonProperty("inline_context") + @ExcludeMissing + inlineContext: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + ) : this(code, inlineContext, name, mutableMapOf()) + /** * The inline code to execute * @@ -5416,22 +5574,15 @@ private constructor( */ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): InlineCode = apply { - if (validated) { - return@apply - } - - code() - inlineContext().validate() - name() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -5546,24 +5697,40 @@ private constructor( checkRequired("code", code), checkRequired("inlineContext", inlineContext), name, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } - @NoAutoDetect + private var validated: Boolean = false + + fun validate(): InlineCode = apply { + if (validated) { + return@apply + } + + code() + inlineContext().validate() + name() + validated = true + } + class InlineContext - @JsonCreator private constructor( - @JsonProperty("runtime") - @ExcludeMissing - private val runtime: JsonField = JsonMissing.of(), - @JsonProperty("version") - @ExcludeMissing - private val version: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val runtime: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("runtime") + @ExcludeMissing + runtime: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + version: JsonField = JsonMissing.of(), + ) : this(runtime, version, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type * or is unexpectedly missing or null (e.g. if the server responded with an @@ -5596,21 +5763,15 @@ private constructor( */ @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): InlineContext = apply { - if (validated) { - return@apply - } - - runtime() - version() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -5703,10 +5864,22 @@ private constructor( InlineContext( checkRequired("runtime", runtime), checkRequired("version", version), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): InlineContext = apply { + if (validated) { + return@apply + } + + runtime() + version() + validated = true + } + class Runtime @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -5850,20 +6023,21 @@ private constructor( } /** Inline prompt definition */ - @NoAutoDetect class InlinePrompt - @JsonCreator private constructor( - @JsonProperty("inline_prompt") - @ExcludeMissing - private val inlinePrompt: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val inlinePrompt: JsonField, + private val name: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("inline_prompt") + @ExcludeMissing + inlinePrompt: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + ) : this(inlinePrompt, name, mutableMapOf()) + /** * The prompt, model, and its parameters * @@ -5898,21 +6072,15 @@ private constructor( */ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): InlinePrompt = apply { - if (validated) { - return@apply - } - - inlinePrompt().ifPresent { it.validate() } - name() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -6015,10 +6183,22 @@ private constructor( InlinePrompt( checkRequired("inlinePrompt", inlinePrompt), name, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): InlinePrompt = apply { + if (validated) { + return@apply + } + + inlinePrompt().ifPresent { it.validate() } + name() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -6042,20 +6222,21 @@ private constructor( * Optional settings for collecting git metadata. By default, will collect all git metadata * fields allowed in org-level settings. */ - @NoAutoDetect class GitMetadataSettings - @JsonCreator private constructor( - @JsonProperty("collect") - @ExcludeMissing - private val collect: JsonField = JsonMissing.of(), - @JsonProperty("fields") - @ExcludeMissing - private val fields: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val collect: JsonField, + private val fields: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("collect") @ExcludeMissing collect: JsonField = JsonMissing.of(), + @JsonProperty("fields") + @ExcludeMissing + fields: JsonField> = JsonMissing.of(), + ) : this(collect, fields, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). @@ -6082,21 +6263,15 @@ private constructor( */ @JsonProperty("fields") @ExcludeMissing fun _fields(): JsonField> = fields + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): GitMetadataSettings = apply { - if (validated) { - return@apply - } - - collect() - fields() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -6198,10 +6373,22 @@ private constructor( GitMetadataSettings( checkRequired("collect", collect), (fields ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): GitMetadataSettings = apply { + if (validated) { + return@apply + } + + collect() + fields() + validated = true + } + class Collect @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -6477,27 +6664,20 @@ private constructor( * Optional experiment-level metadata to store about the evaluation. You can later use this to * slice & dice across experiments. */ - @NoAutoDetect class Metadata - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -6541,7 +6721,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { @@ -6703,26 +6893,31 @@ private constructor( } /** Span parent properties */ - @NoAutoDetect class SpanParentStruct - @JsonCreator private constructor( - @JsonProperty("object_id") - @ExcludeMissing - private val objectId: JsonField = JsonMissing.of(), - @JsonProperty("object_type") - @ExcludeMissing - private val objectType: JsonField = JsonMissing.of(), - @JsonProperty("propagated_event") - @ExcludeMissing - private val propagatedEvent: JsonField = JsonMissing.of(), - @JsonProperty("row_ids") - @ExcludeMissing - private val rowIds: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val objectId: JsonField, + private val objectType: JsonField, + private val propagatedEvent: JsonField, + private val rowIds: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("object_id") + @ExcludeMissing + objectId: JsonField = JsonMissing.of(), + @JsonProperty("object_type") + @ExcludeMissing + objectType: JsonField = JsonMissing.of(), + @JsonProperty("propagated_event") + @ExcludeMissing + propagatedEvent: JsonField = JsonMissing.of(), + @JsonProperty("row_ids") + @ExcludeMissing + rowIds: JsonField = JsonMissing.of(), + ) : this(objectId, objectType, propagatedEvent, rowIds, mutableMapOf()) + /** * The id of the container object you are logging to * @@ -6791,23 +6986,15 @@ private constructor( */ @JsonProperty("row_ids") @ExcludeMissing fun _rowIds(): JsonField = rowIds + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): SpanParentStruct = apply { - if (validated) { - return@apply - } - - objectId() - objectType() - propagatedEvent().ifPresent { it.validate() } - rowIds().ifPresent { it.validate() } - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -6945,10 +7132,24 @@ private constructor( checkRequired("objectType", objectType), propagatedEvent, rowIds, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): SpanParentStruct = apply { + if (validated) { + return@apply + } + + objectId() + objectType() + propagatedEvent().ifPresent { it.validate() } + rowIds().ifPresent { it.validate() } + validated = true + } + class ObjectType @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -7061,27 +7262,20 @@ private constructor( } /** Include these properties in every span created under this parent */ - @NoAutoDetect class PropagatedEvent - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): PropagatedEvent = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -7131,7 +7325,17 @@ private constructor( * Further updates to this [Builder] will not mutate the returned instance. */ fun build(): PropagatedEvent = - PropagatedEvent(additionalProperties.toImmutable()) + PropagatedEvent(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): PropagatedEvent = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { @@ -7153,23 +7357,25 @@ private constructor( } /** Identifiers for the row to to log a subspan under */ - @NoAutoDetect class RowIds - @JsonCreator private constructor( - @JsonProperty("id") - @ExcludeMissing - private val id: JsonField = JsonMissing.of(), - @JsonProperty("root_span_id") - @ExcludeMissing - private val rootSpanId: JsonField = JsonMissing.of(), - @JsonProperty("span_id") - @ExcludeMissing - private val spanId: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val rootSpanId: JsonField, + private val spanId: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("root_span_id") + @ExcludeMissing + rootSpanId: JsonField = JsonMissing.of(), + @JsonProperty("span_id") + @ExcludeMissing + spanId: JsonField = JsonMissing.of(), + ) : this(id, rootSpanId, spanId, mutableMapOf()) + /** * The id of the row * @@ -7222,22 +7428,15 @@ private constructor( */ @JsonProperty("span_id") @ExcludeMissing fun _spanId(): JsonField = spanId + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): RowIds = apply { - if (validated) { - return@apply - } - - id() - rootSpanId() - spanId() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -7351,10 +7550,23 @@ private constructor( checkRequired("id", id), checkRequired("rootSpanId", rootSpanId), checkRequired("spanId", spanId), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): RowIds = apply { + if (validated) { + return@apply + } + + id() + rootSpanId() + spanId() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Experiment.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Experiment.kt index 78d87c27..c7edbb88 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Experiment.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Experiment.kt @@ -6,65 +6,81 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class Experiment -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing private val name: JsonField = JsonMissing.of(), - @JsonProperty("project_id") - @ExcludeMissing - private val projectId: JsonField = JsonMissing.of(), - @JsonProperty("public") - @ExcludeMissing - private val public_: JsonField = JsonMissing.of(), - @JsonProperty("base_exp_id") - @ExcludeMissing - private val baseExpId: JsonField = JsonMissing.of(), - @JsonProperty("commit") - @ExcludeMissing - private val commit: JsonField = JsonMissing.of(), - @JsonProperty("created") - @ExcludeMissing - private val created: JsonField = JsonMissing.of(), - @JsonProperty("dataset_id") - @ExcludeMissing - private val datasetId: JsonField = JsonMissing.of(), - @JsonProperty("dataset_version") - @ExcludeMissing - private val datasetVersion: JsonField = JsonMissing.of(), - @JsonProperty("deleted_at") - @ExcludeMissing - private val deletedAt: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("metadata") - @ExcludeMissing - private val metadata: JsonField = JsonMissing.of(), - @JsonProperty("repo_info") - @ExcludeMissing - private val repoInfo: JsonField = JsonMissing.of(), - @JsonProperty("user_id") - @ExcludeMissing - private val userId: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val name: JsonField, + private val projectId: JsonField, + private val public_: JsonField, + private val baseExpId: JsonField, + private val commit: JsonField, + private val created: JsonField, + private val datasetId: JsonField, + private val datasetVersion: JsonField, + private val deletedAt: JsonField, + private val description: JsonField, + private val metadata: JsonField, + private val repoInfo: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("project_id") @ExcludeMissing projectId: JsonField = JsonMissing.of(), + @JsonProperty("public") @ExcludeMissing public_: JsonField = JsonMissing.of(), + @JsonProperty("base_exp_id") + @ExcludeMissing + baseExpId: JsonField = JsonMissing.of(), + @JsonProperty("commit") @ExcludeMissing commit: JsonField = JsonMissing.of(), + @JsonProperty("created") + @ExcludeMissing + created: JsonField = JsonMissing.of(), + @JsonProperty("dataset_id") @ExcludeMissing datasetId: JsonField = JsonMissing.of(), + @JsonProperty("dataset_version") + @ExcludeMissing + datasetVersion: JsonField = JsonMissing.of(), + @JsonProperty("deleted_at") + @ExcludeMissing + deletedAt: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("repo_info") @ExcludeMissing repoInfo: JsonField = JsonMissing.of(), + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), + ) : this( + id, + name, + projectId, + public_, + baseExpId, + commit, + created, + datasetId, + datasetVersion, + deletedAt, + description, + metadata, + repoInfo, + userId, + mutableMapOf(), + ) + /** * Unique identifier for the experiment * @@ -284,33 +300,15 @@ private constructor( */ @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Experiment = apply { - if (validated) { - return@apply - } - - id() - name() - projectId() - public_() - baseExpId() - commit() - created() - datasetId() - datasetVersion() - deletedAt() - description() - metadata().ifPresent { it.validate() } - repoInfo().ifPresent { it.validate() } - userId() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -623,32 +621,49 @@ private constructor( metadata, repoInfo, userId, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Experiment = apply { + if (validated) { + return@apply + } + + id() + name() + projectId() + public_() + baseExpId() + commit() + created() + datasetId() + datasetVersion() + deletedAt() + description() + metadata().ifPresent { it.validate() } + repoInfo().ifPresent { it.validate() } + userId() + validated = true + } + /** User-controlled metadata about the experiment */ - @NoAutoDetect class Metadata - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -692,7 +707,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentCreateParams.kt index bee4ab93..32189c2d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentCreateParams.kt @@ -6,18 +6,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -193,890 +191,907 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body + fun toBuilder() = Builder().from(this) - override fun _headers(): Headers = additionalHeaders + companion object { - override fun _queryParams(): QueryParams = additionalQueryParams + /** + * Returns a mutable builder for constructing an instance of [ExperimentCreateParams]. + * + * The following fields are required: + * ```java + * .projectId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("project_id") - @ExcludeMissing - private val projectId: JsonField = JsonMissing.of(), - @JsonProperty("base_exp_id") - @ExcludeMissing - private val baseExpId: JsonField = JsonMissing.of(), - @JsonProperty("dataset_id") - @ExcludeMissing - private val datasetId: JsonField = JsonMissing.of(), - @JsonProperty("dataset_version") - @ExcludeMissing - private val datasetVersion: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("ensure_new") - @ExcludeMissing - private val ensureNew: JsonField = JsonMissing.of(), - @JsonProperty("metadata") - @ExcludeMissing - private val metadata: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("public") - @ExcludeMissing - private val public_: JsonField = JsonMissing.of(), - @JsonProperty("repo_info") - @ExcludeMissing - private val repoInfo: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + /** A builder for [ExperimentCreateParams]. */ + class Builder internal constructor() { + + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(experimentCreateParams: ExperimentCreateParams) = apply { + body = experimentCreateParams.body.toBuilder() + additionalHeaders = experimentCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = experimentCreateParams.additionalQueryParams.toBuilder() + } + + /** Unique identifier for the project that the experiment belongs under */ + fun projectId(projectId: String) = apply { body.projectId(projectId) } /** - * Unique identifier for the project that the experiment belongs under + * Sets [Builder.projectId] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + * You should usually call [Builder.projectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun projectId(): String = projectId.getRequired("project_id") + fun projectId(projectId: JsonField) = apply { body.projectId(projectId) } + + /** Id of default base experiment to compare against when viewing this experiment */ + fun baseExpId(baseExpId: String?) = apply { body.baseExpId(baseExpId) } + + /** Alias for calling [Builder.baseExpId] with `baseExpId.orElse(null)`. */ + fun baseExpId(baseExpId: Optional) = baseExpId(baseExpId.getOrNull()) /** - * Id of default base experiment to compare against when viewing this experiment + * Sets [Builder.baseExpId] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.baseExpId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun baseExpId(): Optional = - Optional.ofNullable(baseExpId.getNullable("base_exp_id")) + fun baseExpId(baseExpId: JsonField) = apply { body.baseExpId(baseExpId) } /** * Identifier of the linked dataset, or null if the experiment is not linked to a dataset + */ + fun datasetId(datasetId: String?) = apply { body.datasetId(datasetId) } + + /** Alias for calling [Builder.datasetId] with `datasetId.orElse(null)`. */ + fun datasetId(datasetId: Optional) = datasetId(datasetId.getOrNull()) + + /** + * Sets [Builder.datasetId] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.datasetId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun datasetId(): Optional = Optional.ofNullable(datasetId.getNullable("dataset_id")) + fun datasetId(datasetId: JsonField) = apply { body.datasetId(datasetId) } /** * Version number of the linked dataset the experiment was run against. This can be used to * reproduce the experiment after the dataset has been modified. + */ + fun datasetVersion(datasetVersion: String?) = apply { body.datasetVersion(datasetVersion) } + + /** Alias for calling [Builder.datasetVersion] with `datasetVersion.orElse(null)`. */ + fun datasetVersion(datasetVersion: Optional) = + datasetVersion(datasetVersion.getOrNull()) + + /** + * Sets [Builder.datasetVersion] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.datasetVersion] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun datasetVersion(): Optional = - Optional.ofNullable(datasetVersion.getNullable("dataset_version")) + fun datasetVersion(datasetVersion: JsonField) = apply { + body.datasetVersion(datasetVersion) + } + + /** Textual description of the experiment */ + fun description(description: String?) = apply { body.description(description) } + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) /** - * Textual description of the experiment + * Sets [Builder.description] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(description: JsonField) = apply { body.description(description) } /** * Normally, creating an experiment with the same name as an existing experiment will return * the existing one un-modified. But if `ensure_new` is true, registration will generate a * new experiment with a unique name in case of a conflict. - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). */ - fun ensureNew(): Optional = - Optional.ofNullable(ensureNew.getNullable("ensure_new")) + fun ensureNew(ensureNew: Boolean?) = apply { body.ensureNew(ensureNew) } /** - * User-controlled metadata about the experiment + * Alias for [Builder.ensureNew]. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * This unboxed primitive overload exists for backwards compatibility. */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun ensureNew(ensureNew: Boolean) = ensureNew(ensureNew as Boolean?) - /** - * Name of the experiment. Within a project, experiment names are unique - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + /** Alias for calling [Builder.ensureNew] with `ensureNew.orElse(null)`. */ + fun ensureNew(ensureNew: Optional) = ensureNew(ensureNew.getOrNull()) /** - * Whether or not the experiment is public. Public experiments can be viewed by anybody - * inside or outside the organization + * Sets [Builder.ensureNew] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.ensureNew] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun public_(): Optional = Optional.ofNullable(public_.getNullable("public")) + fun ensureNew(ensureNew: JsonField) = apply { body.ensureNew(ensureNew) } - /** - * Metadata about the state of the repo when the experiment was created - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun repoInfo(): Optional = Optional.ofNullable(repoInfo.getNullable("repo_info")) + /** User-controlled metadata about the experiment */ + fun metadata(metadata: Metadata?) = apply { body.metadata(metadata) } - /** - * Returns the raw JSON value of [projectId]. - * - * Unlike [projectId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("project_id") @ExcludeMissing fun _projectId(): JsonField = projectId + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) /** - * Returns the raw JSON value of [baseExpId]. + * Sets [Builder.metadata] to an arbitrary JSON value. * - * Unlike [baseExpId], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("base_exp_id") @ExcludeMissing fun _baseExpId(): JsonField = baseExpId + fun metadata(metadata: JsonField) = apply { body.metadata(metadata) } - /** - * Returns the raw JSON value of [datasetId]. - * - * Unlike [datasetId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("dataset_id") @ExcludeMissing fun _datasetId(): JsonField = datasetId + /** Name of the experiment. Within a project, experiment names are unique */ + fun name(name: String?) = apply { body.name(name) } - /** - * Returns the raw JSON value of [datasetVersion]. - * - * Unlike [datasetVersion], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("dataset_version") - @ExcludeMissing - fun _datasetVersion(): JsonField = datasetVersion + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) /** - * Returns the raw JSON value of [description]. + * Sets [Builder.name] to an arbitrary JSON value. * - * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("description") - @ExcludeMissing - fun _description(): JsonField = description + fun name(name: JsonField) = apply { body.name(name) } /** - * Returns the raw JSON value of [ensureNew]. - * - * Unlike [ensureNew], this method doesn't throw if the JSON field has an unexpected type. + * Whether or not the experiment is public. Public experiments can be viewed by anybody + * inside or outside the organization */ - @JsonProperty("ensure_new") @ExcludeMissing fun _ensureNew(): JsonField = ensureNew + fun public_(public_: Boolean?) = apply { body.public_(public_) } /** - * Returns the raw JSON value of [metadata]. + * Alias for [Builder.public_]. * - * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + * This unboxed primitive overload exists for backwards compatibility. */ - @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + fun public_(public_: Boolean) = public_(public_ as Boolean?) - /** - * Returns the raw JSON value of [name]. - * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + /** Alias for calling [Builder.public_] with `public_.orElse(null)`. */ + fun public_(public_: Optional) = public_(public_.getOrNull()) /** - * Returns the raw JSON value of [public_]. + * Sets [Builder.public_] to an arbitrary JSON value. * - * Unlike [public_], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.public_] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("public") @ExcludeMissing fun _public_(): JsonField = public_ + fun public_(public_: JsonField) = apply { body.public_(public_) } + + /** Metadata about the state of the repo when the experiment was created */ + fun repoInfo(repoInfo: RepoInfo?) = apply { body.repoInfo(repoInfo) } + + /** Alias for calling [Builder.repoInfo] with `repoInfo.orElse(null)`. */ + fun repoInfo(repoInfo: Optional) = repoInfo(repoInfo.getOrNull()) /** - * Returns the raw JSON value of [repoInfo]. + * Sets [Builder.repoInfo] to an arbitrary JSON value. * - * Unlike [repoInfo], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.repoInfo] with a well-typed [RepoInfo] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("repo_info") @ExcludeMissing fun _repoInfo(): JsonField = repoInfo - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun repoInfo(repoInfo: JsonField) = apply { body.repoInfo(repoInfo) } - private var validated: Boolean = false + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } - fun validate(): Body = apply { - if (validated) { - return@apply - } - - projectId() - baseExpId() - datasetId() - datasetVersion() - description() - ensureNew() - metadata().ifPresent { it.validate() } - name() - public_() - repoInfo().ifPresent { it.validate() } - validated = true - } - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .projectId() - * ``` - */ - @JvmStatic fun builder() = Builder() + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) } - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var projectId: JsonField? = null - private var baseExpId: JsonField = JsonMissing.of() - private var datasetId: JsonField = JsonMissing.of() - private var datasetVersion: JsonField = JsonMissing.of() - private var description: JsonField = JsonMissing.of() - private var ensureNew: JsonField = JsonMissing.of() - private var metadata: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var public_: JsonField = JsonMissing.of() - private var repoInfo: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - projectId = body.projectId - baseExpId = body.baseExpId - datasetId = body.datasetId - datasetVersion = body.datasetVersion - description = body.description - ensureNew = body.ensureNew - metadata = body.metadata - name = body.name - public_ = body.public_ - repoInfo = body.repoInfo - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** Unique identifier for the project that the experiment belongs under */ - fun projectId(projectId: String) = projectId(JsonField.of(projectId)) - - /** - * Sets [Builder.projectId] to an arbitrary JSON value. - * - * You should usually call [Builder.projectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun projectId(projectId: JsonField) = apply { this.projectId = projectId } - - /** Id of default base experiment to compare against when viewing this experiment */ - fun baseExpId(baseExpId: String?) = baseExpId(JsonField.ofNullable(baseExpId)) - - /** Alias for calling [Builder.baseExpId] with `baseExpId.orElse(null)`. */ - fun baseExpId(baseExpId: Optional) = baseExpId(baseExpId.getOrNull()) - - /** - * Sets [Builder.baseExpId] to an arbitrary JSON value. - * - * You should usually call [Builder.baseExpId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun baseExpId(baseExpId: JsonField) = apply { this.baseExpId = baseExpId } - - /** - * Identifier of the linked dataset, or null if the experiment is not linked to a - * dataset - */ - fun datasetId(datasetId: String?) = datasetId(JsonField.ofNullable(datasetId)) - - /** Alias for calling [Builder.datasetId] with `datasetId.orElse(null)`. */ - fun datasetId(datasetId: Optional) = datasetId(datasetId.getOrNull()) - - /** - * Sets [Builder.datasetId] to an arbitrary JSON value. - * - * You should usually call [Builder.datasetId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun datasetId(datasetId: JsonField) = apply { this.datasetId = datasetId } - - /** - * Version number of the linked dataset the experiment was run against. This can be used - * to reproduce the experiment after the dataset has been modified. - */ - fun datasetVersion(datasetVersion: String?) = - datasetVersion(JsonField.ofNullable(datasetVersion)) - - /** Alias for calling [Builder.datasetVersion] with `datasetVersion.orElse(null)`. */ - fun datasetVersion(datasetVersion: Optional) = - datasetVersion(datasetVersion.getOrNull()) - - /** - * Sets [Builder.datasetVersion] to an arbitrary JSON value. - * - * You should usually call [Builder.datasetVersion] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun datasetVersion(datasetVersion: JsonField) = apply { - this.datasetVersion = datasetVersion - } - - /** Textual description of the experiment */ - fun description(description: String?) = description(JsonField.ofNullable(description)) - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) - - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun description(description: JsonField) = apply { - this.description = description + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) } - /** - * Normally, creating an experiment with the same name as an existing experiment will - * return the existing one un-modified. But if `ensure_new` is true, registration will - * generate a new experiment with a unique name in case of a conflict. - */ - fun ensureNew(ensureNew: Boolean?) = ensureNew(JsonField.ofNullable(ensureNew)) - - /** - * Alias for [Builder.ensureNew]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun ensureNew(ensureNew: Boolean) = ensureNew(ensureNew as Boolean?) - - /** Alias for calling [Builder.ensureNew] with `ensureNew.orElse(null)`. */ - fun ensureNew(ensureNew: Optional) = ensureNew(ensureNew.getOrNull()) - - /** - * Sets [Builder.ensureNew] to an arbitrary JSON value. - * - * You should usually call [Builder.ensureNew] with a well-typed [Boolean] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun ensureNew(ensureNew: JsonField) = apply { this.ensureNew = ensureNew } - - /** User-controlled metadata about the experiment */ - fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ - fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** Name of the experiment. Within a project, experiment names are unique */ - fun name(name: String?) = name(JsonField.ofNullable(name)) + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** Alias for calling [Builder.name] with `name.orElse(null)`. */ - fun name(name: Optional) = name(name.getOrNull()) + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - /** - * Whether or not the experiment is public. Public experiments can be viewed by anybody - * inside or outside the organization - */ - fun public_(public_: Boolean?) = public_(JsonField.ofNullable(public_)) + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** - * Alias for [Builder.public_]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun public_(public_: Boolean) = public_(public_ as Boolean?) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** Alias for calling [Builder.public_] with `public_.orElse(null)`. */ - fun public_(public_: Optional) = public_(public_.getOrNull()) + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - /** - * Sets [Builder.public_] to an arbitrary JSON value. - * - * You should usually call [Builder.public_] with a well-typed [Boolean] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun public_(public_: JsonField) = apply { this.public_ = public_ } + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** Metadata about the state of the repo when the experiment was created */ - fun repoInfo(repoInfo: RepoInfo?) = repoInfo(JsonField.ofNullable(repoInfo)) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** Alias for calling [Builder.repoInfo] with `repoInfo.orElse(null)`. */ - fun repoInfo(repoInfo: Optional) = repoInfo(repoInfo.getOrNull()) + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Sets [Builder.repoInfo] to an arbitrary JSON value. - * - * You should usually call [Builder.repoInfo] with a well-typed [RepoInfo] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun repoInfo(repoInfo: JsonField) = apply { this.repoInfo = repoInfo } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .projectId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("projectId", projectId), - baseExpId, - datasetId, - datasetVersion, - description, - ensureNew, - metadata, - name, - public_, - repoInfo, - additionalProperties.toImmutable(), - ) + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - return /* spotless:off */ other is Body && projectId == other.projectId && baseExpId == other.baseExpId && datasetId == other.datasetId && datasetVersion == other.datasetVersion && description == other.description && ensureNew == other.ensureNew && metadata == other.metadata && name == other.name && public_ == other.public_ && repoInfo == other.repoInfo && additionalProperties == other.additionalProperties /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(projectId, baseExpId, datasetId, datasetVersion, description, ensureNew, metadata, name, public_, repoInfo, additionalProperties) } - /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } - override fun hashCode(): Int = hashCode + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - override fun toString() = - "Body{projectId=$projectId, baseExpId=$baseExpId, datasetId=$datasetId, datasetVersion=$datasetVersion, description=$description, ensureNew=$ensureNew, metadata=$metadata, name=$name, public_=$public_, repoInfo=$repoInfo, additionalProperties=$additionalProperties}" - } + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - fun toBuilder() = Builder().from(this) + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - companion object { + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } /** - * Returns a mutable builder for constructing an instance of [ExperimentCreateParams]. + * Returns an immutable instance of [ExperimentCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java * .projectId() * ``` + * + * @throws IllegalStateException if any required field is unset. */ - @JvmStatic fun builder() = Builder() + fun build(): ExperimentCreateParams = + ExperimentCreateParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) } - /** A builder for [ExperimentCreateParams]. */ - @NoAutoDetect - class Builder internal constructor() { + @JvmSynthetic internal fun _body(): Body = body - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun from(experimentCreateParams: ExperimentCreateParams) = apply { - body = experimentCreateParams.body.toBuilder() - additionalHeaders = experimentCreateParams.additionalHeaders.toBuilder() - additionalQueryParams = experimentCreateParams.additionalQueryParams.toBuilder() - } + override fun _queryParams(): QueryParams = additionalQueryParams - /** Unique identifier for the project that the experiment belongs under */ - fun projectId(projectId: String) = apply { body.projectId(projectId) } + class Body + private constructor( + private val projectId: JsonField, + private val baseExpId: JsonField, + private val datasetId: JsonField, + private val datasetVersion: JsonField, + private val description: JsonField, + private val ensureNew: JsonField, + private val metadata: JsonField, + private val name: JsonField, + private val public_: JsonField, + private val repoInfo: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("base_exp_id") + @ExcludeMissing + baseExpId: JsonField = JsonMissing.of(), + @JsonProperty("dataset_id") + @ExcludeMissing + datasetId: JsonField = JsonMissing.of(), + @JsonProperty("dataset_version") + @ExcludeMissing + datasetVersion: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("ensure_new") + @ExcludeMissing + ensureNew: JsonField = JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("public") @ExcludeMissing public_: JsonField = JsonMissing.of(), + @JsonProperty("repo_info") + @ExcludeMissing + repoInfo: JsonField = JsonMissing.of(), + ) : this( + projectId, + baseExpId, + datasetId, + datasetVersion, + description, + ensureNew, + metadata, + name, + public_, + repoInfo, + mutableMapOf(), + ) /** - * Sets [Builder.projectId] to an arbitrary JSON value. + * Unique identifier for the project that the experiment belongs under * - * You should usually call [Builder.projectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun projectId(projectId: JsonField) = apply { body.projectId(projectId) } - - /** Id of default base experiment to compare against when viewing this experiment */ - fun baseExpId(baseExpId: String?) = apply { body.baseExpId(baseExpId) } - - /** Alias for calling [Builder.baseExpId] with `baseExpId.orElse(null)`. */ - fun baseExpId(baseExpId: Optional) = baseExpId(baseExpId.getOrNull()) + fun projectId(): String = projectId.getRequired("project_id") /** - * Sets [Builder.baseExpId] to an arbitrary JSON value. + * Id of default base experiment to compare against when viewing this experiment * - * You should usually call [Builder.baseExpId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun baseExpId(baseExpId: JsonField) = apply { body.baseExpId(baseExpId) } + fun baseExpId(): Optional = + Optional.ofNullable(baseExpId.getNullable("base_exp_id")) /** * Identifier of the linked dataset, or null if the experiment is not linked to a dataset + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun datasetId(datasetId: String?) = apply { body.datasetId(datasetId) } + fun datasetId(): Optional = Optional.ofNullable(datasetId.getNullable("dataset_id")) - /** Alias for calling [Builder.datasetId] with `datasetId.orElse(null)`. */ - fun datasetId(datasetId: Optional) = datasetId(datasetId.getOrNull()) + /** + * Version number of the linked dataset the experiment was run against. This can be used to + * reproduce the experiment after the dataset has been modified. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun datasetVersion(): Optional = + Optional.ofNullable(datasetVersion.getNullable("dataset_version")) /** - * Sets [Builder.datasetId] to an arbitrary JSON value. + * Textual description of the experiment * - * You should usually call [Builder.datasetId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun datasetId(datasetId: JsonField) = apply { body.datasetId(datasetId) } + fun description(): Optional = + Optional.ofNullable(description.getNullable("description")) /** - * Version number of the linked dataset the experiment was run against. This can be used to - * reproduce the experiment after the dataset has been modified. + * Normally, creating an experiment with the same name as an existing experiment will return + * the existing one un-modified. But if `ensure_new` is true, registration will generate a + * new experiment with a unique name in case of a conflict. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun datasetVersion(datasetVersion: String?) = apply { body.datasetVersion(datasetVersion) } + fun ensureNew(): Optional = + Optional.ofNullable(ensureNew.getNullable("ensure_new")) - /** Alias for calling [Builder.datasetVersion] with `datasetVersion.orElse(null)`. */ - fun datasetVersion(datasetVersion: Optional) = - datasetVersion(datasetVersion.getOrNull()) + /** + * User-controlled metadata about the experiment + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) /** - * Sets [Builder.datasetVersion] to an arbitrary JSON value. + * Name of the experiment. Within a project, experiment names are unique * - * You should usually call [Builder.datasetVersion] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun datasetVersion(datasetVersion: JsonField) = apply { - body.datasetVersion(datasetVersion) - } + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) - /** Textual description of the experiment */ - fun description(description: String?) = apply { body.description(description) } + /** + * Whether or not the experiment is public. Public experiments can be viewed by anybody + * inside or outside the organization + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun public_(): Optional = Optional.ofNullable(public_.getNullable("public")) - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) + /** + * Metadata about the state of the repo when the experiment was created + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun repoInfo(): Optional = Optional.ofNullable(repoInfo.getNullable("repo_info")) /** - * Sets [Builder.description] to an arbitrary JSON value. + * Returns the raw JSON value of [projectId]. * - * You should usually call [Builder.description] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [projectId], this method doesn't throw if the JSON field has an unexpected type. */ - fun description(description: JsonField) = apply { body.description(description) } + @JsonProperty("project_id") @ExcludeMissing fun _projectId(): JsonField = projectId /** - * Normally, creating an experiment with the same name as an existing experiment will return - * the existing one un-modified. But if `ensure_new` is true, registration will generate a - * new experiment with a unique name in case of a conflict. + * Returns the raw JSON value of [baseExpId]. + * + * Unlike [baseExpId], this method doesn't throw if the JSON field has an unexpected type. */ - fun ensureNew(ensureNew: Boolean?) = apply { body.ensureNew(ensureNew) } + @JsonProperty("base_exp_id") @ExcludeMissing fun _baseExpId(): JsonField = baseExpId /** - * Alias for [Builder.ensureNew]. + * Returns the raw JSON value of [datasetId]. * - * This unboxed primitive overload exists for backwards compatibility. + * Unlike [datasetId], this method doesn't throw if the JSON field has an unexpected type. */ - fun ensureNew(ensureNew: Boolean) = ensureNew(ensureNew as Boolean?) - - /** Alias for calling [Builder.ensureNew] with `ensureNew.orElse(null)`. */ - fun ensureNew(ensureNew: Optional) = ensureNew(ensureNew.getOrNull()) + @JsonProperty("dataset_id") @ExcludeMissing fun _datasetId(): JsonField = datasetId /** - * Sets [Builder.ensureNew] to an arbitrary JSON value. + * Returns the raw JSON value of [datasetVersion]. * - * You should usually call [Builder.ensureNew] with a well-typed [Boolean] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [datasetVersion], this method doesn't throw if the JSON field has an unexpected + * type. */ - fun ensureNew(ensureNew: JsonField) = apply { body.ensureNew(ensureNew) } - - /** User-controlled metadata about the experiment */ - fun metadata(metadata: Metadata?) = apply { body.metadata(metadata) } - - /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ - fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + @JsonProperty("dataset_version") + @ExcludeMissing + fun _datasetVersion(): JsonField = datasetVersion /** - * Sets [Builder.metadata] to an arbitrary JSON value. + * Returns the raw JSON value of [description]. * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. */ - fun metadata(metadata: JsonField) = apply { body.metadata(metadata) } - - /** Name of the experiment. Within a project, experiment names are unique */ - fun name(name: String?) = apply { body.name(name) } - - /** Alias for calling [Builder.name] with `name.orElse(null)`. */ - fun name(name: Optional) = name(name.getOrNull()) + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description /** - * Sets [Builder.name] to an arbitrary JSON value. + * Returns the raw JSON value of [ensureNew]. * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [ensureNew], this method doesn't throw if the JSON field has an unexpected type. */ - fun name(name: JsonField) = apply { body.name(name) } + @JsonProperty("ensure_new") @ExcludeMissing fun _ensureNew(): JsonField = ensureNew /** - * Whether or not the experiment is public. Public experiments can be viewed by anybody - * inside or outside the organization + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. */ - fun public_(public_: Boolean?) = apply { body.public_(public_) } + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata /** - * Alias for [Builder.public_]. + * Returns the raw JSON value of [name]. * - * This unboxed primitive overload exists for backwards compatibility. + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. */ - fun public_(public_: Boolean) = public_(public_ as Boolean?) - - /** Alias for calling [Builder.public_] with `public_.orElse(null)`. */ - fun public_(public_: Optional) = public_(public_.getOrNull()) + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name /** - * Sets [Builder.public_] to an arbitrary JSON value. + * Returns the raw JSON value of [public_]. * - * You should usually call [Builder.public_] with a well-typed [Boolean] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [public_], this method doesn't throw if the JSON field has an unexpected type. */ - fun public_(public_: JsonField) = apply { body.public_(public_) } - - /** Metadata about the state of the repo when the experiment was created */ - fun repoInfo(repoInfo: RepoInfo?) = apply { body.repoInfo(repoInfo) } - - /** Alias for calling [Builder.repoInfo] with `repoInfo.orElse(null)`. */ - fun repoInfo(repoInfo: Optional) = repoInfo(repoInfo.getOrNull()) + @JsonProperty("public") @ExcludeMissing fun _public_(): JsonField = public_ /** - * Sets [Builder.repoInfo] to an arbitrary JSON value. + * Returns the raw JSON value of [repoInfo]. * - * You should usually call [Builder.repoInfo] with a well-typed [RepoInfo] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [repoInfo], this method doesn't throw if the JSON field has an unexpected type. */ - fun repoInfo(repoInfo: JsonField) = apply { body.repoInfo(repoInfo) } + @JsonProperty("repo_info") @ExcludeMissing fun _repoInfo(): JsonField = repoInfo - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .projectId() + * ``` + */ + @JvmStatic fun builder() = Builder() } - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var projectId: JsonField? = null + private var baseExpId: JsonField = JsonMissing.of() + private var datasetId: JsonField = JsonMissing.of() + private var datasetVersion: JsonField = JsonMissing.of() + private var description: JsonField = JsonMissing.of() + private var ensureNew: JsonField = JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var public_: JsonField = JsonMissing.of() + private var repoInfo: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + projectId = body.projectId + baseExpId = body.baseExpId + datasetId = body.datasetId + datasetVersion = body.datasetVersion + description = body.description + ensureNew = body.ensureNew + metadata = body.metadata + name = body.name + public_ = body.public_ + repoInfo = body.repoInfo + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** Unique identifier for the project that the experiment belongs under */ + fun projectId(projectId: String) = projectId(JsonField.of(projectId)) + + /** + * Sets [Builder.projectId] to an arbitrary JSON value. + * + * You should usually call [Builder.projectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun projectId(projectId: JsonField) = apply { this.projectId = projectId } + + /** Id of default base experiment to compare against when viewing this experiment */ + fun baseExpId(baseExpId: String?) = baseExpId(JsonField.ofNullable(baseExpId)) + + /** Alias for calling [Builder.baseExpId] with `baseExpId.orElse(null)`. */ + fun baseExpId(baseExpId: Optional) = baseExpId(baseExpId.getOrNull()) + + /** + * Sets [Builder.baseExpId] to an arbitrary JSON value. + * + * You should usually call [Builder.baseExpId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun baseExpId(baseExpId: JsonField) = apply { this.baseExpId = baseExpId } + + /** + * Identifier of the linked dataset, or null if the experiment is not linked to a + * dataset + */ + fun datasetId(datasetId: String?) = datasetId(JsonField.ofNullable(datasetId)) + + /** Alias for calling [Builder.datasetId] with `datasetId.orElse(null)`. */ + fun datasetId(datasetId: Optional) = datasetId(datasetId.getOrNull()) + + /** + * Sets [Builder.datasetId] to an arbitrary JSON value. + * + * You should usually call [Builder.datasetId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun datasetId(datasetId: JsonField) = apply { this.datasetId = datasetId } + + /** + * Version number of the linked dataset the experiment was run against. This can be used + * to reproduce the experiment after the dataset has been modified. + */ + fun datasetVersion(datasetVersion: String?) = + datasetVersion(JsonField.ofNullable(datasetVersion)) + + /** Alias for calling [Builder.datasetVersion] with `datasetVersion.orElse(null)`. */ + fun datasetVersion(datasetVersion: Optional) = + datasetVersion(datasetVersion.getOrNull()) + + /** + * Sets [Builder.datasetVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.datasetVersion] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun datasetVersion(datasetVersion: JsonField) = apply { + this.datasetVersion = datasetVersion + } + + /** Textual description of the experiment */ + fun description(description: String?) = description(JsonField.ofNullable(description)) + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } + + /** + * Normally, creating an experiment with the same name as an existing experiment will + * return the existing one un-modified. But if `ensure_new` is true, registration will + * generate a new experiment with a unique name in case of a conflict. + */ + fun ensureNew(ensureNew: Boolean?) = ensureNew(JsonField.ofNullable(ensureNew)) + + /** + * Alias for [Builder.ensureNew]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun ensureNew(ensureNew: Boolean) = ensureNew(ensureNew as Boolean?) + + /** Alias for calling [Builder.ensureNew] with `ensureNew.orElse(null)`. */ + fun ensureNew(ensureNew: Optional) = ensureNew(ensureNew.getOrNull()) + + /** + * Sets [Builder.ensureNew] to an arbitrary JSON value. + * + * You should usually call [Builder.ensureNew] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun ensureNew(ensureNew: JsonField) = apply { this.ensureNew = ensureNew } - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) - } + /** User-controlled metadata about the experiment */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** Name of the experiment. Within a project, experiment names are unique */ + fun name(name: String?) = name(JsonField.ofNullable(name)) - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } + /** + * Whether or not the experiment is public. Public experiments can be viewed by anybody + * inside or outside the organization + */ + fun public_(public_: Boolean?) = public_(JsonField.ofNullable(public_)) - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** + * Alias for [Builder.public_]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun public_(public_: Boolean) = public_(public_ as Boolean?) - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** Alias for calling [Builder.public_] with `public_.orElse(null)`. */ + fun public_(public_: Optional) = public_(public_.getOrNull()) - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } + /** + * Sets [Builder.public_] to an arbitrary JSON value. + * + * You should usually call [Builder.public_] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun public_(public_: JsonField) = apply { this.public_ = public_ } - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } + /** Metadata about the state of the repo when the experiment was created */ + fun repoInfo(repoInfo: RepoInfo?) = repoInfo(JsonField.ofNullable(repoInfo)) - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** Alias for calling [Builder.repoInfo] with `repoInfo.orElse(null)`. */ + fun repoInfo(repoInfo: Optional) = repoInfo(repoInfo.getOrNull()) - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** + * Sets [Builder.repoInfo] to an arbitrary JSON value. + * + * You should usually call [Builder.repoInfo] with a well-typed [RepoInfo] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun repoInfo(repoInfo: JsonField) = apply { this.repoInfo = repoInfo } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .projectId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("projectId", projectId), + baseExpId, + datasetId, + datasetVersion, + description, + ensureNew, + metadata, + name, + public_, + repoInfo, + additionalProperties.toMutableMap(), + ) } - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } + private var validated: Boolean = false - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + fun validate(): Body = apply { + if (validated) { + return@apply } - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) + projectId() + baseExpId() + datasetId() + datasetVersion() + description() + ensureNew() + metadata().ifPresent { it.validate() } + name() + public_() + repoInfo().ifPresent { it.validate() } + validated = true } - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + return /* spotless:off */ other is Body && projectId == other.projectId && baseExpId == other.baseExpId && datasetId == other.datasetId && datasetVersion == other.datasetVersion && description == other.description && ensureNew == other.ensureNew && metadata == other.metadata && name == other.name && public_ == other.public_ && repoInfo == other.repoInfo && additionalProperties == other.additionalProperties /* spotless:on */ } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) - } - - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(projectId, baseExpId, datasetId, datasetVersion, description, ensureNew, metadata, name, public_, repoInfo, additionalProperties) } + /* spotless:on */ - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) - } + override fun hashCode(): Int = hashCode - /** - * Returns an immutable instance of [ExperimentCreateParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .projectId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ExperimentCreateParams = - ExperimentCreateParams( - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + override fun toString() = + "Body{projectId=$projectId, baseExpId=$baseExpId, datasetId=$datasetId, datasetVersion=$datasetVersion, description=$description, ensureNew=$ensureNew, metadata=$metadata, name=$name, public_=$public_, repoInfo=$repoInfo, additionalProperties=$additionalProperties}" } /** User-controlled metadata about the experiment */ - @NoAutoDetect class Metadata - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1120,7 +1135,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentDeleteParams.kt index 7ec99c28..c71f8065 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentDeleteParams.kt @@ -2,13 +2,15 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.toImmutable +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import java.util.Collections import java.util.Objects import java.util.Optional @@ -18,7 +20,7 @@ private constructor( private val experimentId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: Map, + private val additionalBodyProperties: MutableMap, ) : Params { /** Experiment id */ @@ -28,21 +30,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _additionalBodyProperties(): Map = additionalBodyProperties - - @JvmSynthetic - internal fun _body(): Optional> = - Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - - fun _pathParam(index: Int): String = - when (index) { - 0 -> experimentId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders + @JsonAnySetter + private fun putAdditionalBodyProperty(key: String, value: JsonValue) { + additionalBodyProperties.put(key, value) + } - override fun _queryParams(): QueryParams = additionalQueryParams + @JsonAnyGetter + @ExcludeMissing + fun _additionalBodyProperties(): Map = + Collections.unmodifiableMap(additionalBodyProperties) fun toBuilder() = Builder().from(this) @@ -60,7 +56,6 @@ private constructor( } /** A builder for [ExperimentDeleteParams]. */ - @NoAutoDetect class Builder internal constructor() { private var experimentId: String? = null @@ -217,10 +212,24 @@ private constructor( checkRequired("experimentId", experimentId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toImmutable(), + additionalBodyProperties.toMutableMap(), ) } + @JvmSynthetic + internal fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> experimentId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentEvent.kt index aa0f500c..beb9b9aa 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentEvent.kt @@ -6,10 +6,8 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter @@ -17,67 +15,94 @@ import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class ExperimentEvent -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("_xact_id") - @ExcludeMissing - private val _xactId: JsonField = JsonMissing.of(), - @JsonProperty("created") - @ExcludeMissing - private val created: JsonField = JsonMissing.of(), - @JsonProperty("experiment_id") - @ExcludeMissing - private val experimentId: JsonField = JsonMissing.of(), - @JsonProperty("project_id") - @ExcludeMissing - private val projectId: JsonField = JsonMissing.of(), - @JsonProperty("root_span_id") - @ExcludeMissing - private val rootSpanId: JsonField = JsonMissing.of(), - @JsonProperty("span_id") - @ExcludeMissing - private val spanId: JsonField = JsonMissing.of(), - @JsonProperty("context") - @ExcludeMissing - private val context: JsonField = JsonMissing.of(), - @JsonProperty("error") @ExcludeMissing private val error: JsonValue = JsonMissing.of(), - @JsonProperty("expected") @ExcludeMissing private val expected: JsonValue = JsonMissing.of(), - @JsonProperty("input") @ExcludeMissing private val input: JsonValue = JsonMissing.of(), - @JsonProperty("is_root") - @ExcludeMissing - private val isRoot: JsonField = JsonMissing.of(), - @JsonProperty("metadata") - @ExcludeMissing - private val metadata: JsonField = JsonMissing.of(), - @JsonProperty("metrics") - @ExcludeMissing - private val metrics: JsonField = JsonMissing.of(), - @JsonProperty("origin") - @ExcludeMissing - private val origin: JsonField = JsonMissing.of(), - @JsonProperty("output") @ExcludeMissing private val output: JsonValue = JsonMissing.of(), - @JsonProperty("scores") - @ExcludeMissing - private val scores: JsonField = JsonMissing.of(), - @JsonProperty("span_attributes") - @ExcludeMissing - private val spanAttributes: JsonField = JsonMissing.of(), - @JsonProperty("span_parents") - @ExcludeMissing - private val spanParents: JsonField> = JsonMissing.of(), - @JsonProperty("tags") - @ExcludeMissing - private val tags: JsonField> = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val _xactId: JsonField, + private val created: JsonField, + private val experimentId: JsonField, + private val projectId: JsonField, + private val rootSpanId: JsonField, + private val spanId: JsonField, + private val context: JsonField, + private val error: JsonValue, + private val expected: JsonValue, + private val input: JsonValue, + private val isRoot: JsonField, + private val metadata: JsonField, + private val metrics: JsonField, + private val origin: JsonField, + private val output: JsonValue, + private val scores: JsonField, + private val spanAttributes: JsonField, + private val spanParents: JsonField>, + private val tags: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("_xact_id") @ExcludeMissing _xactId: JsonField = JsonMissing.of(), + @JsonProperty("created") + @ExcludeMissing + created: JsonField = JsonMissing.of(), + @JsonProperty("experiment_id") + @ExcludeMissing + experimentId: JsonField = JsonMissing.of(), + @JsonProperty("project_id") @ExcludeMissing projectId: JsonField = JsonMissing.of(), + @JsonProperty("root_span_id") + @ExcludeMissing + rootSpanId: JsonField = JsonMissing.of(), + @JsonProperty("span_id") @ExcludeMissing spanId: JsonField = JsonMissing.of(), + @JsonProperty("context") @ExcludeMissing context: JsonField = JsonMissing.of(), + @JsonProperty("error") @ExcludeMissing error: JsonValue = JsonMissing.of(), + @JsonProperty("expected") @ExcludeMissing expected: JsonValue = JsonMissing.of(), + @JsonProperty("input") @ExcludeMissing input: JsonValue = JsonMissing.of(), + @JsonProperty("is_root") @ExcludeMissing isRoot: JsonField = JsonMissing.of(), + @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("metrics") @ExcludeMissing metrics: JsonField = JsonMissing.of(), + @JsonProperty("origin") + @ExcludeMissing + origin: JsonField = JsonMissing.of(), + @JsonProperty("output") @ExcludeMissing output: JsonValue = JsonMissing.of(), + @JsonProperty("scores") @ExcludeMissing scores: JsonField = JsonMissing.of(), + @JsonProperty("span_attributes") + @ExcludeMissing + spanAttributes: JsonField = JsonMissing.of(), + @JsonProperty("span_parents") + @ExcludeMissing + spanParents: JsonField> = JsonMissing.of(), + @JsonProperty("tags") @ExcludeMissing tags: JsonField> = JsonMissing.of(), + ) : this( + id, + _xactId, + created, + experimentId, + projectId, + rootSpanId, + spanId, + context, + error, + expected, + input, + isRoot, + metadata, + metrics, + origin, + output, + scores, + spanAttributes, + spanParents, + tags, + mutableMapOf(), + ) + /** * A unique identifier for the experiment event. If you don't provide one, BrainTrust will * generate one for you @@ -376,35 +401,15 @@ private constructor( */ @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): ExperimentEvent = apply { - if (validated) { - return@apply - } - - id() - _xactId() - created() - experimentId() - projectId() - rootSpanId() - spanId() - context().ifPresent { it.validate() } - isRoot() - metadata().ifPresent { it.validate() } - metrics().ifPresent { it.validate() } - origin().ifPresent { it.validate() } - scores().ifPresent { it.validate() } - spanAttributes().ifPresent { it.validate() } - spanParents() - tags() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -852,32 +857,62 @@ private constructor( spanAttributes, (spanParents ?: JsonMissing.of()).map { it.toImmutable() }, (tags ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): ExperimentEvent = apply { + if (validated) { + return@apply + } + + id() + _xactId() + created() + experimentId() + projectId() + rootSpanId() + spanId() + context().ifPresent { it.validate() } + isRoot() + metadata().ifPresent { it.validate() } + metrics().ifPresent { it.validate() } + origin().ifPresent { it.validate() } + scores().ifPresent { it.validate() } + spanAttributes().ifPresent { it.validate() } + spanParents() + tags() + validated = true + } + /** * Context is additional information about the code that produced the experiment event. It is * essentially the textual counterpart to `metrics`. Use the `caller_*` attributes to track the * location in code which produced the experiment event */ - @NoAutoDetect class Context - @JsonCreator private constructor( - @JsonProperty("caller_filename") - @ExcludeMissing - private val callerFilename: JsonField = JsonMissing.of(), - @JsonProperty("caller_functionname") - @ExcludeMissing - private val callerFunctionname: JsonField = JsonMissing.of(), - @JsonProperty("caller_lineno") - @ExcludeMissing - private val callerLineno: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val callerFilename: JsonField, + private val callerFunctionname: JsonField, + private val callerLineno: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("caller_filename") + @ExcludeMissing + callerFilename: JsonField = JsonMissing.of(), + @JsonProperty("caller_functionname") + @ExcludeMissing + callerFunctionname: JsonField = JsonMissing.of(), + @JsonProperty("caller_lineno") + @ExcludeMissing + callerLineno: JsonField = JsonMissing.of(), + ) : this(callerFilename, callerFunctionname, callerLineno, mutableMapOf()) + /** * Name of the file in code where the experiment event was created * @@ -935,22 +970,15 @@ private constructor( @ExcludeMissing fun _callerLineno(): JsonField = callerLineno + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Context = apply { - if (validated) { - return@apply - } - - callerFilename() - callerFunctionname() - callerLineno() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1070,10 +1098,23 @@ private constructor( callerFilename, callerFunctionname, callerLineno, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Context = apply { + if (validated) { + return@apply + } + + callerFilename() + callerFunctionname() + callerLineno() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1099,17 +1140,17 @@ private constructor( * slice/dice later. The values in `metadata` can be any JSON-serializable type, but its keys * must be strings */ - @NoAutoDetect class Metadata - @JsonCreator private constructor( - @JsonProperty("model") - @ExcludeMissing - private val model: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val model: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("model") @ExcludeMissing model: JsonField = JsonMissing.of() + ) : this(model, mutableMapOf()) + /** * The model used for this example * @@ -1125,20 +1166,15 @@ private constructor( */ @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - model() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1199,7 +1235,18 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(model, additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(model, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + model() + validated = true } override fun equals(other: Any?): Boolean { @@ -1225,36 +1272,51 @@ private constructor( * experiment event. Use "start" and "end" to track the time span over which the experiment * event was produced */ - @NoAutoDetect class Metrics - @JsonCreator private constructor( - @JsonProperty("caller_filename") - @ExcludeMissing - private val callerFilename: JsonValue = JsonMissing.of(), - @JsonProperty("caller_functionname") - @ExcludeMissing - private val callerFunctionname: JsonValue = JsonMissing.of(), - @JsonProperty("caller_lineno") - @ExcludeMissing - private val callerLineno: JsonValue = JsonMissing.of(), - @JsonProperty("completion_tokens") - @ExcludeMissing - private val completionTokens: JsonField = JsonMissing.of(), - @JsonProperty("end") @ExcludeMissing private val end: JsonField = JsonMissing.of(), - @JsonProperty("prompt_tokens") - @ExcludeMissing - private val promptTokens: JsonField = JsonMissing.of(), - @JsonProperty("start") - @ExcludeMissing - private val start: JsonField = JsonMissing.of(), - @JsonProperty("tokens") - @ExcludeMissing - private val tokens: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val callerFilename: JsonValue, + private val callerFunctionname: JsonValue, + private val callerLineno: JsonValue, + private val completionTokens: JsonField, + private val end: JsonField, + private val promptTokens: JsonField, + private val start: JsonField, + private val tokens: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("caller_filename") + @ExcludeMissing + callerFilename: JsonValue = JsonMissing.of(), + @JsonProperty("caller_functionname") + @ExcludeMissing + callerFunctionname: JsonValue = JsonMissing.of(), + @JsonProperty("caller_lineno") + @ExcludeMissing + callerLineno: JsonValue = JsonMissing.of(), + @JsonProperty("completion_tokens") + @ExcludeMissing + completionTokens: JsonField = JsonMissing.of(), + @JsonProperty("end") @ExcludeMissing end: JsonField = JsonMissing.of(), + @JsonProperty("prompt_tokens") + @ExcludeMissing + promptTokens: JsonField = JsonMissing.of(), + @JsonProperty("start") @ExcludeMissing start: JsonField = JsonMissing.of(), + @JsonProperty("tokens") @ExcludeMissing tokens: JsonField = JsonMissing.of(), + ) : this( + callerFilename, + callerFunctionname, + callerLineno, + completionTokens, + end, + promptTokens, + start, + tokens, + mutableMapOf(), + ) + /** This metric is deprecated */ @JsonProperty("caller_filename") @ExcludeMissing @@ -1355,24 +1417,15 @@ private constructor( */ @JsonProperty("tokens") @ExcludeMissing fun _tokens(): JsonField = tokens + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Metrics = apply { - if (validated) { - return@apply - } - - completionTokens() - end() - promptTokens() - start() - tokens() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1586,10 +1639,25 @@ private constructor( promptTokens, start, tokens, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Metrics = apply { + if (validated) { + return@apply + } + + completionTokens() + end() + promptTokens() + start() + tokens() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1617,27 +1685,20 @@ private constructor( * whether the summarization was covering similar concepts or not. You can use these scores to * help you sort, filter, and compare experiments */ - @NoAutoDetect class Scores - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Scores = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1681,7 +1742,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Scores = Scores(additionalProperties.toImmutable()) + fun build(): Scores = Scores(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Scores = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParams.kt index 91ebe8bd..4cdb84b8 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParams.kt @@ -6,19 +6,18 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects /** Log feedback for a set of experiment events */ @@ -54,170 +53,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - fun _pathParam(index: Int): String = - when (index) { - 0 -> experimentId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("feedback") - @ExcludeMissing - private val feedback: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { - - /** - * A list of experiment feedback items - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun feedback(): List = feedback.getRequired("feedback") - - /** - * Returns the raw JSON value of [feedback]. - * - * Unlike [feedback], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("feedback") - @ExcludeMissing - fun _feedback(): JsonField> = feedback - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } - - feedback().forEach { it.validate() } - validated = true - } - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .feedback() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var feedback: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - feedback = body.feedback.map { it.toMutableList() } - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** A list of experiment feedback items */ - fun feedback(feedback: List) = feedback(JsonField.of(feedback)) - - /** - * Sets [Builder.feedback] to an arbitrary JSON value. - * - * You should usually call [Builder.feedback] with a well-typed - * `List` value instead. This method is primarily for setting - * the field to an undocumented or not yet supported value. - */ - fun feedback(feedback: JsonField>) = apply { - this.feedback = feedback.map { it.toMutableList() } - } - - /** - * Adds a single [FeedbackExperimentItem] to [Builder.feedback]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addFeedback(feedback: FeedbackExperimentItem) = apply { - this.feedback = - (this.feedback ?: JsonField.of(mutableListOf())).also { - checkKnown("feedback", it).add(feedback) - } - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - 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) - } - - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .feedback() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("feedback", feedback).map { it.toImmutable() }, - additionalProperties.toImmutable(), - ) - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Body && feedback == other.feedback && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(feedback, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Body{feedback=$feedback, additionalProperties=$additionalProperties}" - } - fun toBuilder() = Builder().from(this) companion object { @@ -235,7 +70,6 @@ private constructor( } /** A builder for [ExperimentFeedbackParams]. */ - @NoAutoDetect class Builder internal constructor() { private var experimentId: String? = null @@ -414,6 +248,178 @@ private constructor( ) } + @JvmSynthetic internal fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> experimentId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val feedback: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("feedback") + @ExcludeMissing + feedback: JsonField> = JsonMissing.of() + ) : this(feedback, mutableMapOf()) + + /** + * A list of experiment feedback items + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun feedback(): List = feedback.getRequired("feedback") + + /** + * Returns the raw JSON value of [feedback]. + * + * Unlike [feedback], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("feedback") + @ExcludeMissing + fun _feedback(): JsonField> = feedback + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .feedback() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var feedback: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + feedback = body.feedback.map { it.toMutableList() } + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** A list of experiment feedback items */ + fun feedback(feedback: List) = feedback(JsonField.of(feedback)) + + /** + * Sets [Builder.feedback] to an arbitrary JSON value. + * + * You should usually call [Builder.feedback] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun feedback(feedback: JsonField>) = apply { + this.feedback = feedback.map { it.toMutableList() } + } + + /** + * Adds a single [FeedbackExperimentItem] to [Builder.feedback]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addFeedback(feedback: FeedbackExperimentItem) = apply { + this.feedback = + (this.feedback ?: JsonField.of(mutableListOf())).also { + checkKnown("feedback", it).add(feedback) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .feedback() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("feedback", feedback).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + feedback().forEach { it.validate() } + validated = true + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && feedback == other.feedback && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(feedback, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{feedback=$feedback, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchParams.kt index cd0cb7c7..c96284e4 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchParams.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers @@ -86,25 +85,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _pathParam(index: Int): String = - when (index) { - 0 -> experimentId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = - QueryParams.builder() - .apply { - limit?.let { put("limit", it.toString()) } - maxRootSpanId?.let { put("max_root_span_id", it) } - maxXactId?.let { put("max_xact_id", it) } - version?.let { put("version", it) } - putAll(additionalQueryParams) - } - .build() - fun toBuilder() = Builder().from(this) companion object { @@ -121,7 +101,6 @@ private constructor( } /** A builder for [ExperimentFetchParams]. */ - @NoAutoDetect class Builder internal constructor() { private var experimentId: String? = null @@ -341,6 +320,25 @@ private constructor( ) } + fun _pathParam(index: Int): String = + when (index) { + 0 -> experimentId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + limit?.let { put("limit", it.toString()) } + maxRootSpanId?.let { put("max_root_span_id", it) } + maxXactId?.let { put("max_xact_id", it) } + version?.let { put("version", it) } + putAll(additionalQueryParams) + } + .build() + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParams.kt index 02bb6928..d306f406 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParams.kt @@ -6,18 +6,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -154,40 +152,39 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body + fun toBuilder() = Builder().from(this) - fun _pathParam(index: Int): String = - when (index) { - 0 -> experimentId - else -> "" - } + companion object { - override fun _headers(): Headers = additionalHeaders + /** + * Returns a mutable builder for constructing an instance of [ExperimentFetchPostParams]. + * + * The following fields are required: + * ```java + * .experimentId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun _queryParams(): QueryParams = additionalQueryParams + /** A builder for [ExperimentFetchPostParams]. */ + class Builder internal constructor() { - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("cursor") - @ExcludeMissing - private val cursor: JsonField = JsonMissing.of(), - @JsonProperty("limit") - @ExcludeMissing - private val limit: JsonField = JsonMissing.of(), - @JsonProperty("max_root_span_id") - @ExcludeMissing - private val maxRootSpanId: JsonField = JsonMissing.of(), - @JsonProperty("max_xact_id") - @ExcludeMissing - private val maxXactId: JsonField = JsonMissing.of(), - @JsonProperty("version") - @ExcludeMissing - private val version: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + private var experimentId: String? = null + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(experimentFetchPostParams: ExperimentFetchPostParams) = apply { + experimentId = experimentFetchPostParams.experimentId + body = experimentFetchPostParams.body.toBuilder() + additionalHeaders = experimentFetchPostParams.additionalHeaders.toBuilder() + additionalQueryParams = experimentFetchPostParams.additionalQueryParams.toBuilder() + } + + /** Experiment id */ + fun experimentId(experimentId: String) = apply { this.experimentId = experimentId } /** * An opaque string to be used as a cursor for the next page of results, in order from @@ -195,11 +192,19 @@ private constructor( * * The string can be obtained directly from the `cursor` property of the previous fetch * query + */ + fun cursor(cursor: String?) = apply { body.cursor(cursor) } + + /** Alias for calling [Builder.cursor] with `cursor.orElse(null)`. */ + fun cursor(cursor: Optional) = cursor(cursor.getOrNull()) + + /** + * Sets [Builder.cursor] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.cursor] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun cursor(): Optional = Optional.ofNullable(cursor.getNullable("cursor")) + fun cursor(cursor: JsonField) = apply { body.cursor(cursor) } /** * limit the number of traces fetched @@ -215,11 +220,26 @@ private constructor( * The `limit` parameter controls the number of full traces to return. So you may end up * with more individual rows than the specified limit if you are fetching events containing * traces. + */ + fun limit(limit: Long?) = apply { body.limit(limit) } + + /** + * Alias for [Builder.limit]. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * This unboxed primitive overload exists for backwards compatibility. */ - fun limit(): Optional = Optional.ofNullable(limit.getNullable("limit")) + fun limit(limit: Long) = limit(limit as Long?) + + /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ + fun limit(limit: Optional) = limit(limit.getOrNull()) + + /** + * Sets [Builder.limit] to an arbitrary JSON value. + * + * You should usually call [Builder.limit] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun limit(limit: JsonField) = apply { body.limit(limit) } /** * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor of @@ -232,12 +252,23 @@ private constructor( * cursor for the next page can be found as the row with the minimum (earliest) value of the * tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an overview of * paginating fetch queries. + */ + fun maxRootSpanId(maxRootSpanId: String?) = apply { body.maxRootSpanId(maxRootSpanId) } + + /** Alias for calling [Builder.maxRootSpanId] with `maxRootSpanId.orElse(null)`. */ + fun maxRootSpanId(maxRootSpanId: Optional) = + maxRootSpanId(maxRootSpanId.getOrNull()) + + /** + * Sets [Builder.maxRootSpanId] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.maxRootSpanId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun maxRootSpanId(): Optional = - Optional.ofNullable(maxRootSpanId.getNullable("max_root_span_id")) + fun maxRootSpanId(maxRootSpanId: JsonField) = apply { + body.maxRootSpanId(maxRootSpanId) + } /** * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor of @@ -250,330 +281,212 @@ private constructor( * cursor for the next page can be found as the row with the minimum (earliest) value of the * tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an overview of * paginating fetch queries. + */ + fun maxXactId(maxXactId: String?) = apply { body.maxXactId(maxXactId) } + + /** Alias for calling [Builder.maxXactId] with `maxXactId.orElse(null)`. */ + fun maxXactId(maxXactId: Optional) = maxXactId(maxXactId.getOrNull()) + + /** + * Sets [Builder.maxXactId] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.maxXactId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun maxXactId(): Optional = - Optional.ofNullable(maxXactId.getNullable("max_xact_id")) + fun maxXactId(maxXactId: JsonField) = apply { body.maxXactId(maxXactId) } /** * Retrieve a snapshot of events from a past time * * The version id is essentially a filter on the latest event transaction id. You can use * the `max_xact_id` returned by a past fetch as the version to reproduce that exact fetch. - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). */ - fun version(): Optional = Optional.ofNullable(version.getNullable("version")) + fun version(version: String?) = apply { body.version(version) } - /** - * Returns the raw JSON value of [cursor]. - * - * Unlike [cursor], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("cursor") @ExcludeMissing fun _cursor(): JsonField = cursor + /** Alias for calling [Builder.version] with `version.orElse(null)`. */ + fun version(version: Optional) = version(version.getOrNull()) /** - * Returns the raw JSON value of [limit]. + * Sets [Builder.version] to an arbitrary JSON value. * - * Unlike [limit], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.version] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("limit") @ExcludeMissing fun _limit(): JsonField = limit + fun version(version: JsonField) = apply { body.version(version) } - /** - * Returns the raw JSON value of [maxRootSpanId]. - * - * Unlike [maxRootSpanId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("max_root_span_id") - @ExcludeMissing - fun _maxRootSpanId(): JsonField = maxRootSpanId + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } - /** - * Returns the raw JSON value of [maxXactId]. - * - * Unlike [maxXactId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("max_xact_id") @ExcludeMissing fun _maxXactId(): JsonField = maxXactId + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } - /** - * Returns the raw JSON value of [version]. - * - * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - private var validated: Boolean = false + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } - fun validate(): Body = apply { - if (validated) { - return@apply - } + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - cursor() - limit() - maxRootSpanId() - maxXactId() - version() - validated = true + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun toBuilder() = Builder().from(this) + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } - companion object { + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - /** Returns a mutable builder for constructing an instance of [Body]. */ - @JvmStatic fun builder() = Builder() + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } - /** A builder for [Body]. */ - class Builder internal constructor() { + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - private var cursor: JsonField = JsonMissing.of() - private var limit: JsonField = JsonMissing.of() - private var maxRootSpanId: JsonField = JsonMissing.of() - private var maxXactId: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - @JvmSynthetic - internal fun from(body: Body) = apply { - cursor = body.cursor - limit = body.limit - maxRootSpanId = body.maxRootSpanId - maxXactId = body.maxXactId - version = body.version - additionalProperties = body.additionalProperties.toMutableMap() - } + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** - * An opaque string to be used as a cursor for the next page of results, in order from - * latest to earliest. - * - * The string can be obtained directly from the `cursor` property of the previous fetch - * query - */ - fun cursor(cursor: String?) = cursor(JsonField.ofNullable(cursor)) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** Alias for calling [Builder.cursor] with `cursor.orElse(null)`. */ - fun cursor(cursor: Optional) = cursor(cursor.getOrNull()) + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Sets [Builder.cursor] to an arbitrary JSON value. - * - * You should usually call [Builder.cursor] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun cursor(cursor: JsonField) = apply { this.cursor = cursor } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } - /** - * limit the number of traces fetched - * - * Fetch queries may be paginated if the total result size is expected to be large (e.g. - * project_logs which accumulate over a long time). Note that fetch queries only support - * pagination in descending time order (from latest to earliest `_xact_id`. Furthermore, - * later pages may return rows which showed up in earlier pages, except with an earlier - * `_xact_id`. This happens because pagination occurs over the whole version history of - * the event log. You will most likely want to exclude any such duplicate, outdated rows - * (by `id`) from your combined result set. - * - * The `limit` parameter controls the number of full traces to return. So you may end up - * with more individual rows than the specified limit if you are fetching events - * containing traces. - */ - fun limit(limit: Long?) = limit(JsonField.ofNullable(limit)) - - /** - * Alias for [Builder.limit]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun limit(limit: Long) = limit(limit as Long?) - - /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ - fun limit(limit: Optional) = limit(limit.getOrNull()) - - /** - * Sets [Builder.limit] to an arbitrary JSON value. - * - * You should usually call [Builder.limit] with a well-typed [Long] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun limit(limit: JsonField) = apply { this.limit = limit } - - /** - * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor - * of the explicit 'cursor' returned by object fetch requests. Please prefer the - * 'cursor' argument going forwards. - * - * Together, `max_xact_id` and `max_root_span_id` form a pagination cursor - * - * Since a paginated fetch query returns results in order from latest to earliest, the - * cursor for the next page can be found as the row with the minimum (earliest) value of - * the tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an - * overview of paginating fetch queries. - */ - fun maxRootSpanId(maxRootSpanId: String?) = - maxRootSpanId(JsonField.ofNullable(maxRootSpanId)) - - /** Alias for calling [Builder.maxRootSpanId] with `maxRootSpanId.orElse(null)`. */ - fun maxRootSpanId(maxRootSpanId: Optional) = - maxRootSpanId(maxRootSpanId.getOrNull()) - - /** - * Sets [Builder.maxRootSpanId] to an arbitrary JSON value. - * - * You should usually call [Builder.maxRootSpanId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun maxRootSpanId(maxRootSpanId: JsonField) = apply { - this.maxRootSpanId = maxRootSpanId - } - - /** - * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor - * of the explicit 'cursor' returned by object fetch requests. Please prefer the - * 'cursor' argument going forwards. - * - * Together, `max_xact_id` and `max_root_span_id` form a pagination cursor - * - * Since a paginated fetch query returns results in order from latest to earliest, the - * cursor for the next page can be found as the row with the minimum (earliest) value of - * the tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an - * overview of paginating fetch queries. - */ - fun maxXactId(maxXactId: String?) = maxXactId(JsonField.ofNullable(maxXactId)) - - /** Alias for calling [Builder.maxXactId] with `maxXactId.orElse(null)`. */ - fun maxXactId(maxXactId: Optional) = maxXactId(maxXactId.getOrNull()) - - /** - * Sets [Builder.maxXactId] to an arbitrary JSON value. - * - * You should usually call [Builder.maxXactId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun maxXactId(maxXactId: JsonField) = apply { this.maxXactId = maxXactId } - - /** - * Retrieve a snapshot of events from a past time - * - * The version id is essentially a filter on the latest event transaction id. You can - * use the `max_xact_id` returned by a past fetch as the version to reproduce that exact - * fetch. - */ - fun version(version: String?) = version(JsonField.ofNullable(version)) - - /** Alias for calling [Builder.version] with `version.orElse(null)`. */ - fun version(version: Optional) = version(version.getOrNull()) - - /** - * Sets [Builder.version] to an arbitrary JSON value. - * - * You should usually call [Builder.version] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun version(version: JsonField) = apply { this.version = version } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Body = - Body( - cursor, - limit, - maxRootSpanId, - maxXactId, - version, - additionalProperties.toImmutable(), - ) + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - return /* spotless:off */ other is Body && cursor == other.cursor && limit == other.limit && maxRootSpanId == other.maxRootSpanId && maxXactId == other.maxXactId && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cursor, limit, maxRootSpanId, maxXactId, version, additionalProperties) } - /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } - override fun hashCode(): Int = hashCode + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - override fun toString() = - "Body{cursor=$cursor, limit=$limit, maxRootSpanId=$maxRootSpanId, maxXactId=$maxXactId, version=$version, additionalProperties=$additionalProperties}" - } + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - fun toBuilder() = Builder().from(this) + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - companion object { + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } /** - * Returns a mutable builder for constructing an instance of [ExperimentFetchPostParams]. + * Returns an immutable instance of [ExperimentFetchPostParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java * .experimentId() * ``` + * + * @throws IllegalStateException if any required field is unset. */ - @JvmStatic fun builder() = Builder() + fun build(): ExperimentFetchPostParams = + ExperimentFetchPostParams( + checkRequired("experimentId", experimentId), + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) } - /** A builder for [ExperimentFetchPostParams]. */ - @NoAutoDetect - class Builder internal constructor() { - - private var experimentId: String? = null - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + @JvmSynthetic internal fun _body(): Body = body - @JvmSynthetic - internal fun from(experimentFetchPostParams: ExperimentFetchPostParams) = apply { - experimentId = experimentFetchPostParams.experimentId - body = experimentFetchPostParams.body.toBuilder() - additionalHeaders = experimentFetchPostParams.additionalHeaders.toBuilder() - additionalQueryParams = experimentFetchPostParams.additionalQueryParams.toBuilder() + fun _pathParam(index: Int): String = + when (index) { + 0 -> experimentId + else -> "" } - /** Experiment id */ - fun experimentId(experimentId: String) = apply { this.experimentId = experimentId } + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val cursor: JsonField, + private val limit: JsonField, + private val maxRootSpanId: JsonField, + private val maxXactId: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cursor") @ExcludeMissing cursor: JsonField = JsonMissing.of(), + @JsonProperty("limit") @ExcludeMissing limit: JsonField = JsonMissing.of(), + @JsonProperty("max_root_span_id") + @ExcludeMissing + maxRootSpanId: JsonField = JsonMissing.of(), + @JsonProperty("max_xact_id") + @ExcludeMissing + maxXactId: JsonField = JsonMissing.of(), + @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), + ) : this(cursor, limit, maxRootSpanId, maxXactId, version, mutableMapOf()) /** * An opaque string to be used as a cursor for the next page of results, in order from @@ -581,19 +494,11 @@ private constructor( * * The string can be obtained directly from the `cursor` property of the previous fetch * query - */ - fun cursor(cursor: String?) = apply { body.cursor(cursor) } - - /** Alias for calling [Builder.cursor] with `cursor.orElse(null)`. */ - fun cursor(cursor: Optional) = cursor(cursor.getOrNull()) - - /** - * Sets [Builder.cursor] to an arbitrary JSON value. * - * You should usually call [Builder.cursor] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun cursor(cursor: JsonField) = apply { body.cursor(cursor) } + fun cursor(): Optional = Optional.ofNullable(cursor.getNullable("cursor")) /** * limit the number of traces fetched @@ -609,26 +514,29 @@ private constructor( * The `limit` parameter controls the number of full traces to return. So you may end up * with more individual rows than the specified limit if you are fetching events containing * traces. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun limit(limit: Long?) = apply { body.limit(limit) } + fun limit(): Optional = Optional.ofNullable(limit.getNullable("limit")) /** - * Alias for [Builder.limit]. + * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor of + * the explicit 'cursor' returned by object fetch requests. Please prefer the 'cursor' + * argument going forwards. * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun limit(limit: Long) = limit(limit as Long?) - - /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ - fun limit(limit: Optional) = limit(limit.getOrNull()) - - /** - * Sets [Builder.limit] to an arbitrary JSON value. + * Together, `max_xact_id` and `max_root_span_id` form a pagination cursor * - * You should usually call [Builder.limit] with a well-typed [Long] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Since a paginated fetch query returns results in order from latest to earliest, the + * cursor for the next page can be found as the row with the minimum (earliest) value of the + * tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an overview of + * paginating fetch queries. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun limit(limit: JsonField) = apply { body.limit(limit) } + fun maxRootSpanId(): Optional = + Optional.ofNullable(maxRootSpanId.getNullable("max_root_span_id")) /** * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor of @@ -641,205 +549,300 @@ private constructor( * cursor for the next page can be found as the row with the minimum (earliest) value of the * tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an overview of * paginating fetch queries. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun maxRootSpanId(maxRootSpanId: String?) = apply { body.maxRootSpanId(maxRootSpanId) } - - /** Alias for calling [Builder.maxRootSpanId] with `maxRootSpanId.orElse(null)`. */ - fun maxRootSpanId(maxRootSpanId: Optional) = - maxRootSpanId(maxRootSpanId.getOrNull()) + fun maxXactId(): Optional = + Optional.ofNullable(maxXactId.getNullable("max_xact_id")) /** - * Sets [Builder.maxRootSpanId] to an arbitrary JSON value. + * Retrieve a snapshot of events from a past time * - * You should usually call [Builder.maxRootSpanId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * The version id is essentially a filter on the latest event transaction id. You can use + * the `max_xact_id` returned by a past fetch as the version to reproduce that exact fetch. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun maxRootSpanId(maxRootSpanId: JsonField) = apply { - body.maxRootSpanId(maxRootSpanId) - } + fun version(): Optional = Optional.ofNullable(version.getNullable("version")) /** - * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor of - * the explicit 'cursor' returned by object fetch requests. Please prefer the 'cursor' - * argument going forwards. - * - * Together, `max_xact_id` and `max_root_span_id` form a pagination cursor + * Returns the raw JSON value of [cursor]. * - * Since a paginated fetch query returns results in order from latest to earliest, the - * cursor for the next page can be found as the row with the minimum (earliest) value of the - * tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an overview of - * paginating fetch queries. + * Unlike [cursor], this method doesn't throw if the JSON field has an unexpected type. */ - fun maxXactId(maxXactId: String?) = apply { body.maxXactId(maxXactId) } - - /** Alias for calling [Builder.maxXactId] with `maxXactId.orElse(null)`. */ - fun maxXactId(maxXactId: Optional) = maxXactId(maxXactId.getOrNull()) + @JsonProperty("cursor") @ExcludeMissing fun _cursor(): JsonField = cursor /** - * Sets [Builder.maxXactId] to an arbitrary JSON value. + * Returns the raw JSON value of [limit]. * - * You should usually call [Builder.maxXactId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [limit], this method doesn't throw if the JSON field has an unexpected type. */ - fun maxXactId(maxXactId: JsonField) = apply { body.maxXactId(maxXactId) } + @JsonProperty("limit") @ExcludeMissing fun _limit(): JsonField = limit /** - * Retrieve a snapshot of events from a past time + * Returns the raw JSON value of [maxRootSpanId]. * - * The version id is essentially a filter on the latest event transaction id. You can use - * the `max_xact_id` returned by a past fetch as the version to reproduce that exact fetch. + * Unlike [maxRootSpanId], this method doesn't throw if the JSON field has an unexpected + * type. */ - fun version(version: String?) = apply { body.version(version) } + @JsonProperty("max_root_span_id") + @ExcludeMissing + fun _maxRootSpanId(): JsonField = maxRootSpanId - /** Alias for calling [Builder.version] with `version.orElse(null)`. */ - fun version(version: Optional) = version(version.getOrNull()) + /** + * Returns the raw JSON value of [maxXactId]. + * + * Unlike [maxXactId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("max_xact_id") @ExcludeMissing fun _maxXactId(): JsonField = maxXactId /** - * Sets [Builder.version] to an arbitrary JSON value. + * Returns the raw JSON value of [version]. * - * You should usually call [Builder.version] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. */ - fun version(version: JsonField) = apply { body.version(version) } + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Body]. */ + @JvmStatic fun builder() = Builder() } - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var cursor: JsonField = JsonMissing.of() + private var limit: JsonField = JsonMissing.of() + private var maxRootSpanId: JsonField = JsonMissing.of() + private var maxXactId: JsonField = JsonMissing.of() + private var version: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + cursor = body.cursor + limit = body.limit + maxRootSpanId = body.maxRootSpanId + maxXactId = body.maxXactId + version = body.version + additionalProperties = body.additionalProperties.toMutableMap() } - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + /** + * An opaque string to be used as a cursor for the next page of results, in order from + * latest to earliest. + * + * The string can be obtained directly from the `cursor` property of the previous fetch + * query + */ + fun cursor(cursor: String?) = cursor(JsonField.ofNullable(cursor)) - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } + /** Alias for calling [Builder.cursor] with `cursor.orElse(null)`. */ + fun cursor(cursor: Optional) = cursor(cursor.getOrNull()) - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * Sets [Builder.cursor] to an arbitrary JSON value. + * + * You should usually call [Builder.cursor] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun cursor(cursor: JsonField) = apply { this.cursor = cursor } - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * limit the number of traces fetched + * + * Fetch queries may be paginated if the total result size is expected to be large (e.g. + * project_logs which accumulate over a long time). Note that fetch queries only support + * pagination in descending time order (from latest to earliest `_xact_id`. Furthermore, + * later pages may return rows which showed up in earlier pages, except with an earlier + * `_xact_id`. This happens because pagination occurs over the whole version history of + * the event log. You will most likely want to exclude any such duplicate, outdated rows + * (by `id`) from your combined result set. + * + * The `limit` parameter controls the number of full traces to return. So you may end up + * with more individual rows than the specified limit if you are fetching events + * containing traces. + */ + fun limit(limit: Long?) = limit(JsonField.ofNullable(limit)) - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } + /** + * Alias for [Builder.limit]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun limit(limit: Long) = limit(limit as Long?) - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } + /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ + fun limit(limit: Optional) = limit(limit.getOrNull()) - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** + * Sets [Builder.limit] to an arbitrary JSON value. + * + * You should usually call [Builder.limit] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun limit(limit: JsonField) = apply { this.limit = limit } - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** + * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor + * of the explicit 'cursor' returned by object fetch requests. Please prefer the + * 'cursor' argument going forwards. + * + * Together, `max_xact_id` and `max_root_span_id` form a pagination cursor + * + * Since a paginated fetch query returns results in order from latest to earliest, the + * cursor for the next page can be found as the row with the minimum (earliest) value of + * the tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an + * overview of paginating fetch queries. + */ + fun maxRootSpanId(maxRootSpanId: String?) = + maxRootSpanId(JsonField.ofNullable(maxRootSpanId)) - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } + /** Alias for calling [Builder.maxRootSpanId] with `maxRootSpanId.orElse(null)`. */ + fun maxRootSpanId(maxRootSpanId: Optional) = + maxRootSpanId(maxRootSpanId.getOrNull()) - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } + /** + * Sets [Builder.maxRootSpanId] to an arbitrary JSON value. + * + * You should usually call [Builder.maxRootSpanId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun maxRootSpanId(maxRootSpanId: JsonField) = apply { + this.maxRootSpanId = maxRootSpanId + } - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** + * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor + * of the explicit 'cursor' returned by object fetch requests. Please prefer the + * 'cursor' argument going forwards. + * + * Together, `max_xact_id` and `max_root_span_id` form a pagination cursor + * + * Since a paginated fetch query returns results in order from latest to earliest, the + * cursor for the next page can be found as the row with the minimum (earliest) value of + * the tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an + * overview of paginating fetch queries. + */ + fun maxXactId(maxXactId: String?) = maxXactId(JsonField.ofNullable(maxXactId)) - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** Alias for calling [Builder.maxXactId] with `maxXactId.orElse(null)`. */ + fun maxXactId(maxXactId: Optional) = maxXactId(maxXactId.getOrNull()) - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + /** + * Sets [Builder.maxXactId] to an arbitrary JSON value. + * + * You should usually call [Builder.maxXactId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun maxXactId(maxXactId: JsonField) = apply { this.maxXactId = maxXactId } - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } + /** + * Retrieve a snapshot of events from a past time + * + * The version id is essentially a filter on the latest event transaction id. You can + * use the `max_xact_id` returned by a past fetch as the version to reproduce that exact + * fetch. + */ + fun version(version: String?) = version(JsonField.ofNullable(version)) - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + /** Alias for calling [Builder.version] with `version.orElse(null)`. */ + fun version(version: Optional) = version(version.getOrNull()) - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + /** + * Sets [Builder.version] to an arbitrary JSON value. + * + * You should usually call [Builder.version] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun version(version: JsonField) = apply { this.version = version } - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Body = + Body( + cursor, + limit, + maxRootSpanId, + maxXactId, + version, + additionalProperties.toMutableMap(), + ) } - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } + private var validated: Boolean = false - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + fun validate(): Body = apply { + if (validated) { + return@apply + } + + cursor() + limit() + maxRootSpanId() + maxXactId() + version() + validated = true } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) + return /* spotless:off */ other is Body && cursor == other.cursor && limit == other.limit && maxRootSpanId == other.maxRootSpanId && maxXactId == other.maxXactId && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ } - /** - * Returns an immutable instance of [ExperimentFetchPostParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .experimentId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ExperimentFetchPostParams = - ExperimentFetchPostParams( - checkRequired("experimentId", experimentId), - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(cursor, limit, maxRootSpanId, maxXactId, version, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{cursor=$cursor, limit=$limit, maxRootSpanId=$maxRootSpanId, maxXactId=$maxXactId, version=$version, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentInsertParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentInsertParams.kt index bb1f3275..3478b014 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentInsertParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentInsertParams.kt @@ -6,19 +6,18 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects /** Insert a set of events into the experiment */ @@ -54,169 +53,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - fun _pathParam(index: Int): String = - when (index) { - 0 -> experimentId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("events") - @ExcludeMissing - private val events: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { - - /** - * A list of experiment events to insert - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun events(): List = events.getRequired("events") - - /** - * Returns the raw JSON value of [events]. - * - * Unlike [events], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("events") - @ExcludeMissing - fun _events(): JsonField> = events - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } - - events().forEach { it.validate() } - validated = true - } - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .events() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var events: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - events = body.events.map { it.toMutableList() } - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** A list of experiment events to insert */ - fun events(events: List) = events(JsonField.of(events)) - - /** - * Sets [Builder.events] to an arbitrary JSON value. - * - * You should usually call [Builder.events] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun events(events: JsonField>) = apply { - this.events = events.map { it.toMutableList() } - } - - /** - * Adds a single [InsertExperimentEvent] to [events]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addEvent(event: InsertExperimentEvent) = apply { - events = - (events ?: JsonField.of(mutableListOf())).also { - checkKnown("events", it).add(event) - } - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - 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) - } - - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .events() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("events", events).map { it.toImmutable() }, - additionalProperties.toImmutable(), - ) - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Body && events == other.events && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(events, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = "Body{events=$events, additionalProperties=$additionalProperties}" - } - fun toBuilder() = Builder().from(this) companion object { @@ -234,7 +70,6 @@ private constructor( } /** A builder for [ExperimentInsertParams]. */ - @NoAutoDetect class Builder internal constructor() { private var experimentId: String? = null @@ -411,6 +246,177 @@ private constructor( ) } + @JvmSynthetic internal fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> experimentId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val events: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("events") + @ExcludeMissing + events: JsonField> = JsonMissing.of() + ) : this(events, mutableMapOf()) + + /** + * A list of experiment events to insert + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun events(): List = events.getRequired("events") + + /** + * Returns the raw JSON value of [events]. + * + * Unlike [events], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("events") + @ExcludeMissing + fun _events(): JsonField> = events + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .events() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var events: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + events = body.events.map { it.toMutableList() } + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** A list of experiment events to insert */ + fun events(events: List) = events(JsonField.of(events)) + + /** + * Sets [Builder.events] to an arbitrary JSON value. + * + * You should usually call [Builder.events] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun events(events: JsonField>) = apply { + this.events = events.map { it.toMutableList() } + } + + /** + * Adds a single [InsertExperimentEvent] to [events]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addEvent(event: InsertExperimentEvent) = apply { + events = + (events ?: JsonField.of(mutableListOf())).also { + checkKnown("events", it).add(event) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .events() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("events", events).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + events().forEach { it.validate() } + validated = true + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && events == other.events && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(events, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = "Body{events=$events, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt index 3c803f0b..26da97c0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.blocking.ExperimentService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -90,24 +88,30 @@ private constructor( ) = ExperimentListPage(experimentsService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") - private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -165,7 +169,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt index cfdcebc5..5502e0e2 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.async.ExperimentServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -92,24 +90,30 @@ private constructor( ) = ExperimentListPageAsync(experimentsService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") - private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -169,7 +173,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListParams.kt index 6e2f5bef..7a9a3029 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListParams.kt @@ -5,7 +5,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.BaseDeserializer import com.braintrustdata.api.core.BaseSerializer import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers @@ -83,33 +82,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = - QueryParams.builder() - .apply { - endingBefore?.let { put("ending_before", it) } - experimentName?.let { put("experiment_name", it) } - ids?.accept( - object : Ids.Visitor { - override fun visitString(string: String) { - put("ids", string) - } - - override fun visitStrings(strings: List) { - put("ids", strings.joinToString(",")) - } - } - ) - limit?.let { put("limit", it.toString()) } - orgName?.let { put("org_name", it) } - projectId?.let { put("project_id", it) } - projectName?.let { put("project_name", it) } - startingAfter?.let { put("starting_after", it) } - putAll(additionalQueryParams) - } - .build() - fun toBuilder() = Builder().from(this) companion object { @@ -121,7 +93,6 @@ private constructor( } /** A builder for [ExperimentListParams]. */ - @NoAutoDetect class Builder internal constructor() { private var endingBefore: String? = null @@ -345,6 +316,33 @@ private constructor( ) } + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + endingBefore?.let { put("ending_before", it) } + experimentName?.let { put("experiment_name", it) } + ids?.accept( + object : Ids.Visitor { + override fun visitString(string: String) { + put("ids", string) + } + + override fun visitStrings(strings: List) { + put("ids", strings.joinToString(",")) + } + } + ) + limit?.let { put("limit", it.toString()) } + orgName?.let { put("org_name", it) } + projectId?.let { put("project_id", it) } + projectName?.let { put("project_name", it) } + startingAfter?.let { put("starting_after", it) } + putAll(additionalQueryParams) + } + .build() + /** * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentRetrieveParams.kt index 5f5e010a..6b7a9da3 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentRetrieveParams.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers @@ -24,16 +23,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _pathParam(index: Int): String = - when (index) { - 0 -> experimentId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - fun toBuilder() = Builder().from(this) companion object { @@ -50,7 +39,6 @@ private constructor( } /** A builder for [ExperimentRetrieveParams]. */ - @NoAutoDetect class Builder internal constructor() { private var experimentId: String? = null @@ -185,6 +173,16 @@ private constructor( ) } + fun _pathParam(index: Int): String = + when (index) { + 0 -> experimentId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentSummarizeParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentSummarizeParams.kt index bd6b68fb..3b4de8f0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentSummarizeParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentSummarizeParams.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers @@ -41,23 +40,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _pathParam(index: Int): String = - when (index) { - 0 -> experimentId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = - QueryParams.builder() - .apply { - comparisonExperimentId?.let { put("comparison_experiment_id", it) } - summarizeScores?.let { put("summarize_scores", it.toString()) } - putAll(additionalQueryParams) - } - .build() - fun toBuilder() = Builder().from(this) companion object { @@ -74,7 +56,6 @@ private constructor( } /** A builder for [ExperimentSummarizeParams]. */ - @NoAutoDetect class Builder internal constructor() { private var experimentId: String? = null @@ -251,6 +232,23 @@ private constructor( ) } + fun _pathParam(index: Int): String = + when (index) { + 0 -> experimentId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + comparisonExperimentId?.let { put("comparison_experiment_id", it) } + summarizeScores?.let { put("summarize_scores", it.toString()) } + putAll(additionalQueryParams) + } + .build() + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt index dd47e1cb..fda66de1 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt @@ -6,18 +6,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -166,765 +164,778 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body + fun toBuilder() = Builder().from(this) - fun _pathParam(index: Int): String = - when (index) { - 0 -> experimentId - else -> "" + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ExperimentUpdateParams]. + * + * The following fields are required: + * ```java + * .experimentId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ExperimentUpdateParams]. */ + class Builder internal constructor() { + + private var experimentId: String? = null + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(experimentUpdateParams: ExperimentUpdateParams) = apply { + experimentId = experimentUpdateParams.experimentId + body = experimentUpdateParams.body.toBuilder() + additionalHeaders = experimentUpdateParams.additionalHeaders.toBuilder() + additionalQueryParams = experimentUpdateParams.additionalQueryParams.toBuilder() } - override fun _headers(): Headers = additionalHeaders + /** Experiment id */ + fun experimentId(experimentId: String) = apply { this.experimentId = experimentId } - override fun _queryParams(): QueryParams = additionalQueryParams + /** Id of default base experiment to compare against when viewing this experiment */ + fun baseExpId(baseExpId: String?) = apply { body.baseExpId(baseExpId) } - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("base_exp_id") - @ExcludeMissing - private val baseExpId: JsonField = JsonMissing.of(), - @JsonProperty("dataset_id") - @ExcludeMissing - private val datasetId: JsonField = JsonMissing.of(), - @JsonProperty("dataset_version") - @ExcludeMissing - private val datasetVersion: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("metadata") - @ExcludeMissing - private val metadata: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("public") - @ExcludeMissing - private val public_: JsonField = JsonMissing.of(), - @JsonProperty("repo_info") - @ExcludeMissing - private val repoInfo: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + /** Alias for calling [Builder.baseExpId] with `baseExpId.orElse(null)`. */ + fun baseExpId(baseExpId: Optional) = baseExpId(baseExpId.getOrNull()) /** - * Id of default base experiment to compare against when viewing this experiment + * Sets [Builder.baseExpId] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.baseExpId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun baseExpId(): Optional = - Optional.ofNullable(baseExpId.getNullable("base_exp_id")) + fun baseExpId(baseExpId: JsonField) = apply { body.baseExpId(baseExpId) } /** * Identifier of the linked dataset, or null if the experiment is not linked to a dataset - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). */ - fun datasetId(): Optional = Optional.ofNullable(datasetId.getNullable("dataset_id")) + fun datasetId(datasetId: String?) = apply { body.datasetId(datasetId) } - /** - * Version number of the linked dataset the experiment was run against. This can be used to - * reproduce the experiment after the dataset has been modified. - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun datasetVersion(): Optional = - Optional.ofNullable(datasetVersion.getNullable("dataset_version")) + /** Alias for calling [Builder.datasetId] with `datasetId.orElse(null)`. */ + fun datasetId(datasetId: Optional) = datasetId(datasetId.getOrNull()) /** - * Textual description of the experiment + * Sets [Builder.datasetId] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.datasetId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun datasetId(datasetId: JsonField) = apply { body.datasetId(datasetId) } /** - * User-controlled metadata about the experiment - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * Version number of the linked dataset the experiment was run against. This can be used to + * reproduce the experiment after the dataset has been modified. */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun datasetVersion(datasetVersion: String?) = apply { body.datasetVersion(datasetVersion) } - /** - * Name of the experiment. Within a project, experiment names are unique - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + /** Alias for calling [Builder.datasetVersion] with `datasetVersion.orElse(null)`. */ + fun datasetVersion(datasetVersion: Optional) = + datasetVersion(datasetVersion.getOrNull()) /** - * Whether or not the experiment is public. Public experiments can be viewed by anybody - * inside or outside the organization + * Sets [Builder.datasetVersion] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.datasetVersion] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun public_(): Optional = Optional.ofNullable(public_.getNullable("public")) + fun datasetVersion(datasetVersion: JsonField) = apply { + body.datasetVersion(datasetVersion) + } - /** - * Metadata about the state of the repo when the experiment was created - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun repoInfo(): Optional = Optional.ofNullable(repoInfo.getNullable("repo_info")) + /** Textual description of the experiment */ + fun description(description: String?) = apply { body.description(description) } - /** - * Returns the raw JSON value of [baseExpId]. - * - * Unlike [baseExpId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("base_exp_id") @ExcludeMissing fun _baseExpId(): JsonField = baseExpId + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) /** - * Returns the raw JSON value of [datasetId]. + * Sets [Builder.description] to an arbitrary JSON value. * - * Unlike [datasetId], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("dataset_id") @ExcludeMissing fun _datasetId(): JsonField = datasetId + fun description(description: JsonField) = apply { body.description(description) } + + /** User-controlled metadata about the experiment */ + fun metadata(metadata: Metadata?) = apply { body.metadata(metadata) } + + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) /** - * Returns the raw JSON value of [datasetVersion]. + * Sets [Builder.metadata] to an arbitrary JSON value. * - * Unlike [datasetVersion], this method doesn't throw if the JSON field has an unexpected - * type. + * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("dataset_version") - @ExcludeMissing - fun _datasetVersion(): JsonField = datasetVersion + fun metadata(metadata: JsonField) = apply { body.metadata(metadata) } + + /** Name of the experiment. Within a project, experiment names are unique */ + fun name(name: String?) = apply { body.name(name) } + + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) /** - * Returns the raw JSON value of [description]. + * Sets [Builder.name] to an arbitrary JSON value. * - * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("description") - @ExcludeMissing - fun _description(): JsonField = description + fun name(name: JsonField) = apply { body.name(name) } /** - * Returns the raw JSON value of [metadata]. - * - * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + * Whether or not the experiment is public. Public experiments can be viewed by anybody + * inside or outside the organization */ - @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + fun public_(public_: Boolean?) = apply { body.public_(public_) } /** - * Returns the raw JSON value of [name]. + * Alias for [Builder.public_]. * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + * This unboxed primitive overload exists for backwards compatibility. */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + fun public_(public_: Boolean) = public_(public_ as Boolean?) + + /** Alias for calling [Builder.public_] with `public_.orElse(null)`. */ + fun public_(public_: Optional) = public_(public_.getOrNull()) /** - * Returns the raw JSON value of [public_]. + * Sets [Builder.public_] to an arbitrary JSON value. * - * Unlike [public_], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.public_] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("public") @ExcludeMissing fun _public_(): JsonField = public_ + fun public_(public_: JsonField) = apply { body.public_(public_) } + + /** Metadata about the state of the repo when the experiment was created */ + fun repoInfo(repoInfo: RepoInfo?) = apply { body.repoInfo(repoInfo) } + + /** Alias for calling [Builder.repoInfo] with `repoInfo.orElse(null)`. */ + fun repoInfo(repoInfo: Optional) = repoInfo(repoInfo.getOrNull()) /** - * Returns the raw JSON value of [repoInfo]. + * Sets [Builder.repoInfo] to an arbitrary JSON value. * - * Unlike [repoInfo], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.repoInfo] with a well-typed [RepoInfo] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("repo_info") @ExcludeMissing fun _repoInfo(): JsonField = repoInfo + fun repoInfo(repoInfo: JsonField) = apply { body.repoInfo(repoInfo) } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } - private var validated: Boolean = false + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } - fun validate(): Body = apply { - if (validated) { - return@apply + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) } - baseExpId() - datasetId() - datasetVersion() - description() - metadata().ifPresent { it.validate() } - name() - public_() - repoInfo().ifPresent { it.validate() } - validated = true - } + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - fun toBuilder() = Builder().from(this) + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } - companion object { + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** Returns a mutable builder for constructing an instance of [Body]. */ - @JvmStatic fun builder() = Builder() + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var baseExpId: JsonField = JsonMissing.of() - private var datasetId: JsonField = JsonMissing.of() - private var datasetVersion: JsonField = JsonMissing.of() - private var description: JsonField = JsonMissing.of() - private var metadata: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var public_: JsonField = JsonMissing.of() - private var repoInfo: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - baseExpId = body.baseExpId - datasetId = body.datasetId - datasetVersion = body.datasetVersion - description = body.description - metadata = body.metadata - name = body.name - public_ = body.public_ - repoInfo = body.repoInfo - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** Id of default base experiment to compare against when viewing this experiment */ - fun baseExpId(baseExpId: String?) = baseExpId(JsonField.ofNullable(baseExpId)) - - /** Alias for calling [Builder.baseExpId] with `baseExpId.orElse(null)`. */ - fun baseExpId(baseExpId: Optional) = baseExpId(baseExpId.getOrNull()) - - /** - * Sets [Builder.baseExpId] to an arbitrary JSON value. - * - * You should usually call [Builder.baseExpId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun baseExpId(baseExpId: JsonField) = apply { this.baseExpId = baseExpId } - - /** - * Identifier of the linked dataset, or null if the experiment is not linked to a - * dataset - */ - fun datasetId(datasetId: String?) = datasetId(JsonField.ofNullable(datasetId)) - - /** Alias for calling [Builder.datasetId] with `datasetId.orElse(null)`. */ - fun datasetId(datasetId: Optional) = datasetId(datasetId.getOrNull()) - - /** - * Sets [Builder.datasetId] to an arbitrary JSON value. - * - * You should usually call [Builder.datasetId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun datasetId(datasetId: JsonField) = apply { this.datasetId = datasetId } - - /** - * Version number of the linked dataset the experiment was run against. This can be used - * to reproduce the experiment after the dataset has been modified. - */ - fun datasetVersion(datasetVersion: String?) = - datasetVersion(JsonField.ofNullable(datasetVersion)) - - /** Alias for calling [Builder.datasetVersion] with `datasetVersion.orElse(null)`. */ - fun datasetVersion(datasetVersion: Optional) = - datasetVersion(datasetVersion.getOrNull()) - - /** - * Sets [Builder.datasetVersion] to an arbitrary JSON value. - * - * You should usually call [Builder.datasetVersion] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun datasetVersion(datasetVersion: JsonField) = apply { - this.datasetVersion = datasetVersion - } - - /** Textual description of the experiment */ - fun description(description: String?) = description(JsonField.ofNullable(description)) - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) - - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun description(description: JsonField) = apply { - this.description = description - } - - /** User-controlled metadata about the experiment */ - fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) - - /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ - fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) - - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - - /** Name of the experiment. Within a project, experiment names are unique */ - fun name(name: String?) = name(JsonField.ofNullable(name)) - - /** Alias for calling [Builder.name] with `name.orElse(null)`. */ - fun name(name: Optional) = name(name.getOrNull()) + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - /** - * Whether or not the experiment is public. Public experiments can be viewed by anybody - * inside or outside the organization - */ - fun public_(public_: Boolean?) = public_(JsonField.ofNullable(public_)) + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** - * Alias for [Builder.public_]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun public_(public_: Boolean) = public_(public_ as Boolean?) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** Alias for calling [Builder.public_] with `public_.orElse(null)`. */ - fun public_(public_: Optional) = public_(public_.getOrNull()) + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - /** - * Sets [Builder.public_] to an arbitrary JSON value. - * - * You should usually call [Builder.public_] with a well-typed [Boolean] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun public_(public_: JsonField) = apply { this.public_ = public_ } + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** Metadata about the state of the repo when the experiment was created */ - fun repoInfo(repoInfo: RepoInfo?) = repoInfo(JsonField.ofNullable(repoInfo)) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** Alias for calling [Builder.repoInfo] with `repoInfo.orElse(null)`. */ - fun repoInfo(repoInfo: Optional) = repoInfo(repoInfo.getOrNull()) + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Sets [Builder.repoInfo] to an arbitrary JSON value. - * - * You should usually call [Builder.repoInfo] with a well-typed [RepoInfo] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun repoInfo(repoInfo: JsonField) = apply { this.repoInfo = repoInfo } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Body = - Body( - baseExpId, - datasetId, - datasetVersion, - description, - metadata, - name, - public_, - repoInfo, - additionalProperties.toImmutable(), - ) + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - return /* spotless:off */ other is Body && baseExpId == other.baseExpId && datasetId == other.datasetId && datasetVersion == other.datasetVersion && description == other.description && metadata == other.metadata && name == other.name && public_ == other.public_ && repoInfo == other.repoInfo && additionalProperties == other.additionalProperties /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(baseExpId, datasetId, datasetVersion, description, metadata, name, public_, repoInfo, additionalProperties) } - /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } - override fun hashCode(): Int = hashCode + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - override fun toString() = - "Body{baseExpId=$baseExpId, datasetId=$datasetId, datasetVersion=$datasetVersion, description=$description, metadata=$metadata, name=$name, public_=$public_, repoInfo=$repoInfo, additionalProperties=$additionalProperties}" - } + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - fun toBuilder() = Builder().from(this) + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - companion object { + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } /** - * Returns a mutable builder for constructing an instance of [ExperimentUpdateParams]. + * Returns an immutable instance of [ExperimentUpdateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java * .experimentId() * ``` + * + * @throws IllegalStateException if any required field is unset. */ - @JvmStatic fun builder() = Builder() + fun build(): ExperimentUpdateParams = + ExperimentUpdateParams( + checkRequired("experimentId", experimentId), + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) } - /** A builder for [ExperimentUpdateParams]. */ - @NoAutoDetect - class Builder internal constructor() { - - private var experimentId: String? = null - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + @JvmSynthetic internal fun _body(): Body = body - @JvmSynthetic - internal fun from(experimentUpdateParams: ExperimentUpdateParams) = apply { - experimentId = experimentUpdateParams.experimentId - body = experimentUpdateParams.body.toBuilder() - additionalHeaders = experimentUpdateParams.additionalHeaders.toBuilder() - additionalQueryParams = experimentUpdateParams.additionalQueryParams.toBuilder() + fun _pathParam(index: Int): String = + when (index) { + 0 -> experimentId + else -> "" } - /** Experiment id */ - fun experimentId(experimentId: String) = apply { this.experimentId = experimentId } + override fun _headers(): Headers = additionalHeaders - /** Id of default base experiment to compare against when viewing this experiment */ - fun baseExpId(baseExpId: String?) = apply { body.baseExpId(baseExpId) } + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val baseExpId: JsonField, + private val datasetId: JsonField, + private val datasetVersion: JsonField, + private val description: JsonField, + private val metadata: JsonField, + private val name: JsonField, + private val public_: JsonField, + private val repoInfo: JsonField, + private val additionalProperties: MutableMap, + ) { - /** Alias for calling [Builder.baseExpId] with `baseExpId.orElse(null)`. */ - fun baseExpId(baseExpId: Optional) = baseExpId(baseExpId.getOrNull()) + @JsonCreator + private constructor( + @JsonProperty("base_exp_id") + @ExcludeMissing + baseExpId: JsonField = JsonMissing.of(), + @JsonProperty("dataset_id") + @ExcludeMissing + datasetId: JsonField = JsonMissing.of(), + @JsonProperty("dataset_version") + @ExcludeMissing + datasetVersion: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("public") @ExcludeMissing public_: JsonField = JsonMissing.of(), + @JsonProperty("repo_info") + @ExcludeMissing + repoInfo: JsonField = JsonMissing.of(), + ) : this( + baseExpId, + datasetId, + datasetVersion, + description, + metadata, + name, + public_, + repoInfo, + mutableMapOf(), + ) /** - * Sets [Builder.baseExpId] to an arbitrary JSON value. + * Id of default base experiment to compare against when viewing this experiment * - * You should usually call [Builder.baseExpId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun baseExpId(baseExpId: JsonField) = apply { body.baseExpId(baseExpId) } + fun baseExpId(): Optional = + Optional.ofNullable(baseExpId.getNullable("base_exp_id")) /** * Identifier of the linked dataset, or null if the experiment is not linked to a dataset - */ - fun datasetId(datasetId: String?) = apply { body.datasetId(datasetId) } - - /** Alias for calling [Builder.datasetId] with `datasetId.orElse(null)`. */ - fun datasetId(datasetId: Optional) = datasetId(datasetId.getOrNull()) - - /** - * Sets [Builder.datasetId] to an arbitrary JSON value. * - * You should usually call [Builder.datasetId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun datasetId(datasetId: JsonField) = apply { body.datasetId(datasetId) } + fun datasetId(): Optional = Optional.ofNullable(datasetId.getNullable("dataset_id")) /** * Version number of the linked dataset the experiment was run against. This can be used to * reproduce the experiment after the dataset has been modified. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun datasetVersion(datasetVersion: String?) = apply { body.datasetVersion(datasetVersion) } - - /** Alias for calling [Builder.datasetVersion] with `datasetVersion.orElse(null)`. */ - fun datasetVersion(datasetVersion: Optional) = - datasetVersion(datasetVersion.getOrNull()) + fun datasetVersion(): Optional = + Optional.ofNullable(datasetVersion.getNullable("dataset_version")) /** - * Sets [Builder.datasetVersion] to an arbitrary JSON value. + * Textual description of the experiment * - * You should usually call [Builder.datasetVersion] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun datasetVersion(datasetVersion: JsonField) = apply { - body.datasetVersion(datasetVersion) - } - - /** Textual description of the experiment */ - fun description(description: String?) = apply { body.description(description) } - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) + fun description(): Optional = + Optional.ofNullable(description.getNullable("description")) /** - * Sets [Builder.description] to an arbitrary JSON value. + * User-controlled metadata about the experiment * - * You should usually call [Builder.description] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun description(description: JsonField) = apply { body.description(description) } - - /** User-controlled metadata about the experiment */ - fun metadata(metadata: Metadata?) = apply { body.metadata(metadata) } - - /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ - fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) /** - * Sets [Builder.metadata] to an arbitrary JSON value. + * Name of the experiment. Within a project, experiment names are unique * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun metadata(metadata: JsonField) = apply { body.metadata(metadata) } + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) - /** Name of the experiment. Within a project, experiment names are unique */ - fun name(name: String?) = apply { body.name(name) } + /** + * Whether or not the experiment is public. Public experiments can be viewed by anybody + * inside or outside the organization + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun public_(): Optional = Optional.ofNullable(public_.getNullable("public")) - /** Alias for calling [Builder.name] with `name.orElse(null)`. */ - fun name(name: Optional) = name(name.getOrNull()) + /** + * Metadata about the state of the repo when the experiment was created + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun repoInfo(): Optional = Optional.ofNullable(repoInfo.getNullable("repo_info")) /** - * Sets [Builder.name] to an arbitrary JSON value. + * Returns the raw JSON value of [baseExpId]. * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [baseExpId], this method doesn't throw if the JSON field has an unexpected type. */ - fun name(name: JsonField) = apply { body.name(name) } + @JsonProperty("base_exp_id") @ExcludeMissing fun _baseExpId(): JsonField = baseExpId /** - * Whether or not the experiment is public. Public experiments can be viewed by anybody - * inside or outside the organization + * Returns the raw JSON value of [datasetId]. + * + * Unlike [datasetId], this method doesn't throw if the JSON field has an unexpected type. */ - fun public_(public_: Boolean?) = apply { body.public_(public_) } + @JsonProperty("dataset_id") @ExcludeMissing fun _datasetId(): JsonField = datasetId /** - * Alias for [Builder.public_]. + * Returns the raw JSON value of [datasetVersion]. * - * This unboxed primitive overload exists for backwards compatibility. + * Unlike [datasetVersion], this method doesn't throw if the JSON field has an unexpected + * type. */ - fun public_(public_: Boolean) = public_(public_ as Boolean?) + @JsonProperty("dataset_version") + @ExcludeMissing + fun _datasetVersion(): JsonField = datasetVersion - /** Alias for calling [Builder.public_] with `public_.orElse(null)`. */ - fun public_(public_: Optional) = public_(public_.getOrNull()) + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description /** - * Sets [Builder.public_] to an arbitrary JSON value. + * Returns the raw JSON value of [metadata]. * - * You should usually call [Builder.public_] with a well-typed [Boolean] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. */ - fun public_(public_: JsonField) = apply { body.public_(public_) } + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata - /** Metadata about the state of the repo when the experiment was created */ - fun repoInfo(repoInfo: RepoInfo?) = apply { body.repoInfo(repoInfo) } + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - /** Alias for calling [Builder.repoInfo] with `repoInfo.orElse(null)`. */ - fun repoInfo(repoInfo: Optional) = repoInfo(repoInfo.getOrNull()) + /** + * Returns the raw JSON value of [public_]. + * + * Unlike [public_], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("public") @ExcludeMissing fun _public_(): JsonField = public_ /** - * Sets [Builder.repoInfo] to an arbitrary JSON value. + * Returns the raw JSON value of [repoInfo]. * - * You should usually call [Builder.repoInfo] with a well-typed [RepoInfo] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [repoInfo], this method doesn't throw if the JSON field has an unexpected type. */ - fun repoInfo(repoInfo: JsonField) = apply { body.repoInfo(repoInfo) } + @JsonProperty("repo_info") @ExcludeMissing fun _repoInfo(): JsonField = repoInfo + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Body]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var baseExpId: JsonField = JsonMissing.of() + private var datasetId: JsonField = JsonMissing.of() + private var datasetVersion: JsonField = JsonMissing.of() + private var description: JsonField = JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var public_: JsonField = JsonMissing.of() + private var repoInfo: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + baseExpId = body.baseExpId + datasetId = body.datasetId + datasetVersion = body.datasetVersion + description = body.description + metadata = body.metadata + name = body.name + public_ = body.public_ + repoInfo = body.repoInfo + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** Id of default base experiment to compare against when viewing this experiment */ + fun baseExpId(baseExpId: String?) = baseExpId(JsonField.ofNullable(baseExpId)) + + /** Alias for calling [Builder.baseExpId] with `baseExpId.orElse(null)`. */ + fun baseExpId(baseExpId: Optional) = baseExpId(baseExpId.getOrNull()) + + /** + * Sets [Builder.baseExpId] to an arbitrary JSON value. + * + * You should usually call [Builder.baseExpId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun baseExpId(baseExpId: JsonField) = apply { this.baseExpId = baseExpId } + + /** + * Identifier of the linked dataset, or null if the experiment is not linked to a + * dataset + */ + fun datasetId(datasetId: String?) = datasetId(JsonField.ofNullable(datasetId)) + + /** Alias for calling [Builder.datasetId] with `datasetId.orElse(null)`. */ + fun datasetId(datasetId: Optional) = datasetId(datasetId.getOrNull()) + + /** + * Sets [Builder.datasetId] to an arbitrary JSON value. + * + * You should usually call [Builder.datasetId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun datasetId(datasetId: JsonField) = apply { this.datasetId = datasetId } + + /** + * Version number of the linked dataset the experiment was run against. This can be used + * to reproduce the experiment after the dataset has been modified. + */ + fun datasetVersion(datasetVersion: String?) = + datasetVersion(JsonField.ofNullable(datasetVersion)) + + /** Alias for calling [Builder.datasetVersion] with `datasetVersion.orElse(null)`. */ + fun datasetVersion(datasetVersion: Optional) = + datasetVersion(datasetVersion.getOrNull()) + + /** + * Sets [Builder.datasetVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.datasetVersion] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun datasetVersion(datasetVersion: JsonField) = apply { + this.datasetVersion = datasetVersion + } - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) - } + /** Textual description of the experiment */ + fun description(description: String?) = description(JsonField.ofNullable(description)) - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun description(description: JsonField) = apply { + this.description = description } - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + /** User-controlled metadata about the experiment */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** Name of the experiment. Within a project, experiment names are unique */ + fun name(name: String?) = name(JsonField.ofNullable(name)) - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** + * Whether or not the experiment is public. Public experiments can be viewed by anybody + * inside or outside the organization + */ + fun public_(public_: Boolean?) = public_(JsonField.ofNullable(public_)) - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** + * Alias for [Builder.public_]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun public_(public_: Boolean) = public_(public_ as Boolean?) - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } + /** Alias for calling [Builder.public_] with `public_.orElse(null)`. */ + fun public_(public_: Optional) = public_(public_.getOrNull()) - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } + /** + * Sets [Builder.public_] to an arbitrary JSON value. + * + * You should usually call [Builder.public_] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun public_(public_: JsonField) = apply { this.public_ = public_ } - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** Metadata about the state of the repo when the experiment was created */ + fun repoInfo(repoInfo: RepoInfo?) = repoInfo(JsonField.ofNullable(repoInfo)) - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** Alias for calling [Builder.repoInfo] with `repoInfo.orElse(null)`. */ + fun repoInfo(repoInfo: Optional) = repoInfo(repoInfo.getOrNull()) - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + /** + * Sets [Builder.repoInfo] to an arbitrary JSON value. + * + * You should usually call [Builder.repoInfo] with a well-typed [RepoInfo] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun repoInfo(repoInfo: JsonField) = apply { this.repoInfo = repoInfo } - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Body = + Body( + baseExpId, + datasetId, + datasetVersion, + description, + metadata, + name, + public_, + repoInfo, + additionalProperties.toMutableMap(), + ) } - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply } - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) + baseExpId() + datasetId() + datasetVersion() + description() + metadata().ifPresent { it.validate() } + name() + public_() + repoInfo().ifPresent { it.validate() } + validated = true } - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + return /* spotless:off */ other is Body && baseExpId == other.baseExpId && datasetId == other.datasetId && datasetVersion == other.datasetVersion && description == other.description && metadata == other.metadata && name == other.name && public_ == other.public_ && repoInfo == other.repoInfo && additionalProperties == other.additionalProperties /* spotless:on */ } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) - } - - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(baseExpId, datasetId, datasetVersion, description, metadata, name, public_, repoInfo, additionalProperties) } + /* spotless:on */ - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) - } + override fun hashCode(): Int = hashCode - /** - * Returns an immutable instance of [ExperimentUpdateParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .experimentId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ExperimentUpdateParams = - ExperimentUpdateParams( - checkRequired("experimentId", experimentId), - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + override fun toString() = + "Body{baseExpId=$baseExpId, datasetId=$datasetId, datasetVersion=$datasetVersion, description=$description, metadata=$metadata, name=$name, public_=$public_, repoInfo=$repoInfo, additionalProperties=$additionalProperties}" } /** User-controlled metadata about the experiment */ - @NoAutoDetect class Metadata - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -968,7 +979,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackDatasetItem.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackDatasetItem.kt index 363314e1..291901e8 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackDatasetItem.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackDatasetItem.kt @@ -7,40 +7,38 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class FeedbackDatasetItem -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("comment") - @ExcludeMissing - private val comment: JsonField = JsonMissing.of(), - @JsonProperty("metadata") - @ExcludeMissing - private val metadata: JsonField = JsonMissing.of(), - @JsonProperty("source") - @ExcludeMissing - private val source: JsonField = JsonMissing.of(), - @JsonProperty("tags") - @ExcludeMissing - private val tags: JsonField> = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val comment: JsonField, + private val metadata: JsonField, + private val source: JsonField, + private val tags: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("comment") @ExcludeMissing comment: JsonField = JsonMissing.of(), + @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("source") @ExcludeMissing source: JsonField = JsonMissing.of(), + @JsonProperty("tags") @ExcludeMissing tags: JsonField> = JsonMissing.of(), + ) : this(id, comment, metadata, source, tags, mutableMapOf()) + /** * The id of the dataset event to log feedback for. This is the row `id` returned by `POST * /v1/dataset/{dataset_id}/insert` @@ -119,24 +117,15 @@ private constructor( */ @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): FeedbackDatasetItem = apply { - if (validated) { - return@apply - } - - id() - comment() - metadata().ifPresent { it.validate() } - source() - tags() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -298,36 +287,44 @@ private constructor( metadata, source, (tags ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): FeedbackDatasetItem = apply { + if (validated) { + return@apply + } + + id() + comment() + metadata().ifPresent { it.validate() } + source() + tags() + validated = true + } + /** * A dictionary with additional data about the feedback. If you have a `user_id`, you can log it * here and access it in the Braintrust UI. Note, this metadata does not correspond to the main * event itself, but rather the audit log attached to the event. */ - @NoAutoDetect class Metadata - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -371,7 +368,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackExperimentItem.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackExperimentItem.kt index 406a2fd1..cd33c855 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackExperimentItem.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackExperimentItem.kt @@ -7,44 +7,42 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class FeedbackExperimentItem -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("comment") - @ExcludeMissing - private val comment: JsonField = JsonMissing.of(), - @JsonProperty("expected") @ExcludeMissing private val expected: JsonValue = JsonMissing.of(), - @JsonProperty("metadata") - @ExcludeMissing - private val metadata: JsonField = JsonMissing.of(), - @JsonProperty("scores") - @ExcludeMissing - private val scores: JsonField = JsonMissing.of(), - @JsonProperty("source") - @ExcludeMissing - private val source: JsonField = JsonMissing.of(), - @JsonProperty("tags") - @ExcludeMissing - private val tags: JsonField> = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val comment: JsonField, + private val expected: JsonValue, + private val metadata: JsonField, + private val scores: JsonField, + private val source: JsonField, + private val tags: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("comment") @ExcludeMissing comment: JsonField = JsonMissing.of(), + @JsonProperty("expected") @ExcludeMissing expected: JsonValue = JsonMissing.of(), + @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("scores") @ExcludeMissing scores: JsonField = JsonMissing.of(), + @JsonProperty("source") @ExcludeMissing source: JsonField = JsonMissing.of(), + @JsonProperty("tags") @ExcludeMissing tags: JsonField> = JsonMissing.of(), + ) : this(id, comment, expected, metadata, scores, source, tags, mutableMapOf()) + /** * The id of the experiment event to log feedback for. This is the row `id` returned by `POST * /v1/experiment/{experiment_id}/insert` @@ -145,25 +143,15 @@ private constructor( */ @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): FeedbackExperimentItem = apply { - if (validated) { - return@apply - } - - id() - comment() - metadata().ifPresent { it.validate() } - scores().ifPresent { it.validate() } - source() - tags() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -354,36 +342,45 @@ private constructor( scores, source, (tags ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): FeedbackExperimentItem = apply { + if (validated) { + return@apply + } + + id() + comment() + metadata().ifPresent { it.validate() } + scores().ifPresent { it.validate() } + source() + tags() + validated = true + } + /** * A dictionary with additional data about the feedback. If you have a `user_id`, you can log it * here and access it in the Braintrust UI. Note, this metadata does not correspond to the main * event itself, but rather the audit log attached to the event. */ - @NoAutoDetect class Metadata - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -427,7 +424,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { @@ -451,27 +458,20 @@ private constructor( * A dictionary of numeric values (between 0 and 1) to log. These scores will be merged into the * existing scores for the experiment event */ - @NoAutoDetect class Scores - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Scores = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -515,7 +515,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Scores = Scores(additionalProperties.toImmutable()) + fun build(): Scores = Scores(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Scores = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItem.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItem.kt index 3741b996..5ce7211e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItem.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItem.kt @@ -7,44 +7,42 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class FeedbackProjectLogsItem -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("comment") - @ExcludeMissing - private val comment: JsonField = JsonMissing.of(), - @JsonProperty("expected") @ExcludeMissing private val expected: JsonValue = JsonMissing.of(), - @JsonProperty("metadata") - @ExcludeMissing - private val metadata: JsonField = JsonMissing.of(), - @JsonProperty("scores") - @ExcludeMissing - private val scores: JsonField = JsonMissing.of(), - @JsonProperty("source") - @ExcludeMissing - private val source: JsonField = JsonMissing.of(), - @JsonProperty("tags") - @ExcludeMissing - private val tags: JsonField> = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val comment: JsonField, + private val expected: JsonValue, + private val metadata: JsonField, + private val scores: JsonField, + private val source: JsonField, + private val tags: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("comment") @ExcludeMissing comment: JsonField = JsonMissing.of(), + @JsonProperty("expected") @ExcludeMissing expected: JsonValue = JsonMissing.of(), + @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("scores") @ExcludeMissing scores: JsonField = JsonMissing.of(), + @JsonProperty("source") @ExcludeMissing source: JsonField = JsonMissing.of(), + @JsonProperty("tags") @ExcludeMissing tags: JsonField> = JsonMissing.of(), + ) : this(id, comment, expected, metadata, scores, source, tags, mutableMapOf()) + /** * The id of the project logs event to log feedback for. This is the row `id` returned by `POST * /v1/project_logs/{project_id}/insert` @@ -145,25 +143,15 @@ private constructor( */ @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): FeedbackProjectLogsItem = apply { - if (validated) { - return@apply - } - - id() - comment() - metadata().ifPresent { it.validate() } - scores().ifPresent { it.validate() } - source() - tags() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -354,36 +342,45 @@ private constructor( scores, source, (tags ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): FeedbackProjectLogsItem = apply { + if (validated) { + return@apply + } + + id() + comment() + metadata().ifPresent { it.validate() } + scores().ifPresent { it.validate() } + source() + tags() + validated = true + } + /** * A dictionary with additional data about the feedback. If you have a `user_id`, you can log it * here and access it in the Braintrust UI. Note, this metadata does not correspond to the main * event itself, but rather the audit log attached to the event. */ - @NoAutoDetect class Metadata - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -427,7 +424,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { @@ -451,27 +458,20 @@ private constructor( * A dictionary of numeric values (between 0 and 1) to log. These scores will be merged into the * existing scores for the project logs event */ - @NoAutoDetect class Scores - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Scores = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -515,7 +515,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Scores = Scores(additionalProperties.toImmutable()) + fun build(): Scores = Scores(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Scores = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackResponseSchema.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackResponseSchema.kt index 8bbcb0f7..ed159e98 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackResponseSchema.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackResponseSchema.kt @@ -7,27 +7,26 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects -@NoAutoDetect class FeedbackResponseSchema -@JsonCreator private constructor( - @JsonProperty("status") - @ExcludeMissing - private val status: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val status: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of() + ) : this(status, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). @@ -41,20 +40,15 @@ private constructor( */ @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): FeedbackResponseSchema = apply { - if (validated) { - return@apply - } - - status() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -127,10 +121,21 @@ private constructor( fun build(): FeedbackResponseSchema = FeedbackResponseSchema( checkRequired("status", status), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): FeedbackResponseSchema = apply { + if (validated) { + return@apply + } + + status() + validated = true + } + class Status @JsonCreator private constructor(private val value: JsonField) : Enum { /** diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchDatasetEventsResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchDatasetEventsResponse.kt index 627d9ef7..d369727c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchDatasetEventsResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchDatasetEventsResponse.kt @@ -6,33 +6,34 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class FetchDatasetEventsResponse -@JsonCreator private constructor( - @JsonProperty("events") - @ExcludeMissing - private val events: JsonField> = JsonMissing.of(), - @JsonProperty("cursor") - @ExcludeMissing - private val cursor: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val events: JsonField>, + private val cursor: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("events") + @ExcludeMissing + events: JsonField> = JsonMissing.of(), + @JsonProperty("cursor") @ExcludeMissing cursor: JsonField = JsonMissing.of(), + ) : this(events, cursor, mutableMapOf()) + /** * A list of fetched events * @@ -66,21 +67,15 @@ private constructor( */ @JsonProperty("cursor") @ExcludeMissing fun _cursor(): JsonField = cursor + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): FetchDatasetEventsResponse = apply { - if (validated) { - return@apply - } - - events().forEach { it.validate() } - cursor() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -191,10 +186,22 @@ private constructor( FetchDatasetEventsResponse( checkRequired("events", events).map { it.toImmutable() }, cursor, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): FetchDatasetEventsResponse = apply { + if (validated) { + return@apply + } + + events().forEach { it.validate() } + cursor() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchExperimentEventsResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchExperimentEventsResponse.kt index 585ff788..6fca6b6e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchExperimentEventsResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchExperimentEventsResponse.kt @@ -6,33 +6,34 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class FetchExperimentEventsResponse -@JsonCreator private constructor( - @JsonProperty("events") - @ExcludeMissing - private val events: JsonField> = JsonMissing.of(), - @JsonProperty("cursor") - @ExcludeMissing - private val cursor: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val events: JsonField>, + private val cursor: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("events") + @ExcludeMissing + events: JsonField> = JsonMissing.of(), + @JsonProperty("cursor") @ExcludeMissing cursor: JsonField = JsonMissing.of(), + ) : this(events, cursor, mutableMapOf()) + /** * A list of fetched events * @@ -66,21 +67,15 @@ private constructor( */ @JsonProperty("cursor") @ExcludeMissing fun _cursor(): JsonField = cursor + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): FetchExperimentEventsResponse = apply { - if (validated) { - return@apply - } - - events().forEach { it.validate() } - cursor() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -192,10 +187,22 @@ private constructor( FetchExperimentEventsResponse( checkRequired("events", events).map { it.toImmutable() }, cursor, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): FetchExperimentEventsResponse = apply { + if (validated) { + return@apply + } + + events().forEach { it.validate() } + cursor() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchProjectLogsEventsResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchProjectLogsEventsResponse.kt index 81de5770..aa41a3d7 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchProjectLogsEventsResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchProjectLogsEventsResponse.kt @@ -6,33 +6,34 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class FetchProjectLogsEventsResponse -@JsonCreator private constructor( - @JsonProperty("events") - @ExcludeMissing - private val events: JsonField> = JsonMissing.of(), - @JsonProperty("cursor") - @ExcludeMissing - private val cursor: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val events: JsonField>, + private val cursor: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("events") + @ExcludeMissing + events: JsonField> = JsonMissing.of(), + @JsonProperty("cursor") @ExcludeMissing cursor: JsonField = JsonMissing.of(), + ) : this(events, cursor, mutableMapOf()) + /** * A list of fetched events * @@ -68,21 +69,15 @@ private constructor( */ @JsonProperty("cursor") @ExcludeMissing fun _cursor(): JsonField = cursor + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): FetchProjectLogsEventsResponse = apply { - if (validated) { - return@apply - } - - events().forEach { it.validate() } - cursor() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -195,10 +190,22 @@ private constructor( FetchProjectLogsEventsResponse( checkRequired("events", events).map { it.toImmutable() }, cursor, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): FetchProjectLogsEventsResponse = apply { + if (validated) { + return@apply + } + + events().forEach { it.validate() } + cursor() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Function.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Function.kt index 9811c9a5..105b24aa 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Function.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Function.kt @@ -9,11 +9,9 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter @@ -28,55 +26,82 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class Function -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("_xact_id") - @ExcludeMissing - private val _xactId: JsonField = JsonMissing.of(), - @JsonProperty("function_data") - @ExcludeMissing - private val functionData: JsonField = JsonMissing.of(), - @JsonProperty("log_id") @ExcludeMissing private val logId: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing private val name: JsonField = JsonMissing.of(), - @JsonProperty("org_id") @ExcludeMissing private val orgId: JsonField = JsonMissing.of(), - @JsonProperty("project_id") - @ExcludeMissing - private val projectId: JsonField = JsonMissing.of(), - @JsonProperty("slug") @ExcludeMissing private val slug: JsonField = JsonMissing.of(), - @JsonProperty("created") - @ExcludeMissing - private val created: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("function_schema") - @ExcludeMissing - private val functionSchema: JsonField = JsonMissing.of(), - @JsonProperty("function_type") - @ExcludeMissing - private val functionType: JsonField = JsonMissing.of(), - @JsonProperty("metadata") - @ExcludeMissing - private val metadata: JsonField = JsonMissing.of(), - @JsonProperty("origin") - @ExcludeMissing - private val origin: JsonField = JsonMissing.of(), - @JsonProperty("prompt_data") - @ExcludeMissing - private val promptData: JsonField = JsonMissing.of(), - @JsonProperty("tags") - @ExcludeMissing - private val tags: JsonField> = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val _xactId: JsonField, + private val functionData: JsonField, + private val logId: JsonField, + private val name: JsonField, + private val orgId: JsonField, + private val projectId: JsonField, + private val slug: JsonField, + private val created: JsonField, + private val description: JsonField, + private val functionSchema: JsonField, + private val functionType: JsonField, + private val metadata: JsonField, + private val origin: JsonField, + private val promptData: JsonField, + private val tags: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("_xact_id") @ExcludeMissing _xactId: JsonField = JsonMissing.of(), + @JsonProperty("function_data") + @ExcludeMissing + functionData: JsonField = JsonMissing.of(), + @JsonProperty("log_id") @ExcludeMissing logId: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("org_id") @ExcludeMissing orgId: JsonField = JsonMissing.of(), + @JsonProperty("project_id") @ExcludeMissing projectId: JsonField = JsonMissing.of(), + @JsonProperty("slug") @ExcludeMissing slug: JsonField = JsonMissing.of(), + @JsonProperty("created") + @ExcludeMissing + created: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("function_schema") + @ExcludeMissing + functionSchema: JsonField = JsonMissing.of(), + @JsonProperty("function_type") + @ExcludeMissing + functionType: JsonField = JsonMissing.of(), + @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("origin") @ExcludeMissing origin: JsonField = JsonMissing.of(), + @JsonProperty("prompt_data") + @ExcludeMissing + promptData: JsonField = JsonMissing.of(), + @JsonProperty("tags") @ExcludeMissing tags: JsonField> = JsonMissing.of(), + ) : this( + id, + _xactId, + functionData, + logId, + name, + orgId, + projectId, + slug, + created, + description, + functionSchema, + functionType, + metadata, + origin, + promptData, + tags, + mutableMapOf(), + ) + /** * Unique identifier for the prompt * @@ -325,35 +350,15 @@ private constructor( */ @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Function = apply { - if (validated) { - return@apply - } - - id() - _xactId() - functionData().validate() - logId() - name() - orgId() - projectId() - slug() - created() - description() - functionSchema().ifPresent { it.validate() } - functionType() - metadata().ifPresent { it.validate() } - origin().ifPresent { it.validate() } - promptData().ifPresent { it.validate() } - tags() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -715,10 +720,36 @@ private constructor( origin, promptData, (tags ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Function = apply { + if (validated) { + return@apply + } + + id() + _xactId() + functionData().validate() + logId() + name() + orgId() + projectId() + slug() + created() + description() + functionSchema().ifPresent { it.validate() } + functionType() + metadata().ifPresent { it.validate() } + origin().ifPresent { it.validate() } + promptData().ifPresent { it.validate() } + tags() + validated = true + } + @JsonDeserialize(using = FunctionData.Deserializer::class) @JsonSerialize(using = FunctionData.Serializer::class) class FunctionData @@ -877,17 +908,17 @@ private constructor( } } - @NoAutoDetect class Prompt - @JsonCreator private constructor( - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of() + ) : this(type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -902,20 +933,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Prompt = apply { - if (validated) { - return@apply - } - - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -990,7 +1016,18 @@ private constructor( * @throws IllegalStateException if any required field is unset. */ fun build(): Prompt = - Prompt(checkRequired("type", type), additionalProperties.toImmutable()) + Prompt(checkRequired("type", type), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Prompt = apply { + if (validated) { + return@apply + } + + type() + validated = true } class Type @JsonCreator private constructor(private val value: JsonField) : @@ -1108,20 +1145,19 @@ private constructor( "Prompt{type=$type, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Code - @JsonCreator private constructor( - @JsonProperty("data") - @ExcludeMissing - private val data: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val data: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(data, type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -1150,21 +1186,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Code = apply { - if (validated) { - return@apply - } - - data().validate() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1263,10 +1293,22 @@ private constructor( Code( checkRequired("data", data), checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Code = apply { + if (validated) { + return@apply + } + + data().validate() + type() + validated = true + } + @JsonDeserialize(using = Data.Deserializer::class) @JsonSerialize(using = Data.Serializer::class) class Data @@ -1403,30 +1445,43 @@ private constructor( } } - @NoAutoDetect class Bundle - @JsonCreator private constructor( - @JsonProperty("bundle_id") - @ExcludeMissing - private val bundleId: JsonField = JsonMissing.of(), - @JsonProperty("location") - @ExcludeMissing - private val location: JsonField = JsonMissing.of(), - @JsonProperty("runtime_context") - @ExcludeMissing - private val runtimeContext: JsonField = - JsonMissing.of(), - @JsonProperty("preview") - @ExcludeMissing - private val preview: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val bundleId: JsonField, + private val location: JsonField, + private val runtimeContext: JsonField, + private val preview: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("bundle_id") + @ExcludeMissing + bundleId: JsonField = JsonMissing.of(), + @JsonProperty("location") + @ExcludeMissing + location: JsonField = JsonMissing.of(), + @JsonProperty("runtime_context") + @ExcludeMissing + runtimeContext: JsonField = JsonMissing.of(), + @JsonProperty("preview") + @ExcludeMissing + preview: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + ) : this(bundleId, location, runtimeContext, preview, type, mutableMapOf()) + + fun toCodeBundle(): CodeBundle = + CodeBundle.builder() + .bundleId(bundleId) + .location(location) + .runtimeContext(runtimeContext) + .preview(preview) + .build() + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type or is unexpectedly missing or null (e.g. if the server responded with @@ -1513,32 +1568,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun toCodeBundle(): CodeBundle = - CodeBundle.builder() - .bundleId(bundleId) - .location(location) - .runtimeContext(runtimeContext) - .preview(preview) - .build() - - private var validated: Boolean = false - - fun validate(): Bundle = apply { - if (validated) { - return@apply - } - - bundleId() - location().validate() - runtimeContext().validate() - preview() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1705,10 +1743,25 @@ private constructor( checkRequired("runtimeContext", runtimeContext), preview, checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Bundle = apply { + if (validated) { + return@apply + } + + bundleId() + location().validate() + runtimeContext().validate() + preview() + type() + validated = true + } + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -1828,23 +1881,27 @@ private constructor( "Bundle{bundleId=$bundleId, location=$location, runtimeContext=$runtimeContext, preview=$preview, type=$type, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Inline - @JsonCreator private constructor( - @JsonProperty("code") - @ExcludeMissing - private val code: JsonField = JsonMissing.of(), - @JsonProperty("runtime_context") - @ExcludeMissing - private val runtimeContext: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val code: JsonField, + private val runtimeContext: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("code") + @ExcludeMissing + code: JsonField = JsonMissing.of(), + @JsonProperty("runtime_context") + @ExcludeMissing + runtimeContext: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + ) : this(code, runtimeContext, type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type or is unexpectedly missing or null (e.g. if the server responded with @@ -1893,22 +1950,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Inline = apply { - if (validated) { - return@apply - } - - code() - runtimeContext().validate() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -2021,25 +2071,40 @@ private constructor( checkRequired("code", code), checkRequired("runtimeContext", runtimeContext), checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } - @NoAutoDetect + private var validated: Boolean = false + + fun validate(): Inline = apply { + if (validated) { + return@apply + } + + code() + runtimeContext().validate() + type() + validated = true + } + class RuntimeContext - @JsonCreator private constructor( - @JsonProperty("runtime") - @ExcludeMissing - private val runtime: JsonField = JsonMissing.of(), - @JsonProperty("version") - @ExcludeMissing - private val version: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = - immutableEmptyMap(), + private val runtime: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("runtime") + @ExcludeMissing + runtime: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + version: JsonField = JsonMissing.of(), + ) : this(runtime, version, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an * unexpected type or is unexpectedly missing or null (e.g. if the server @@ -2074,21 +2139,15 @@ private constructor( @ExcludeMissing fun _version(): JsonField = version + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): RuntimeContext = apply { - if (validated) { - return@apply - } - - runtime() - version() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -2189,10 +2248,22 @@ private constructor( RuntimeContext( checkRequired("runtime", runtime), checkRequired("version", version), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): RuntimeContext = apply { + if (validated) { + return@apply + } + + runtime() + version() + validated = true + } + class Runtime @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2558,20 +2629,19 @@ private constructor( "Code{data=$data, type=$type, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Global - @JsonCreator private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val name: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(name, type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -2600,21 +2670,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Global = apply { - if (validated) { - return@apply - } - - name() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -2707,10 +2771,22 @@ private constructor( Global( checkRequired("name", name), checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Global = apply { + if (validated) { + return@apply + } + + name() + type() + validated = true + } + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2923,35 +2999,32 @@ private constructor( } /** JSON schema for the function's parameters and return type */ - @NoAutoDetect class FunctionSchema - @JsonCreator private constructor( - @JsonProperty("parameters") - @ExcludeMissing - private val parameters: JsonValue = JsonMissing.of(), - @JsonProperty("returns") @ExcludeMissing private val returns: JsonValue = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val parameters: JsonValue, + private val returns: JsonValue, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("parameters") @ExcludeMissing parameters: JsonValue = JsonMissing.of(), + @JsonProperty("returns") @ExcludeMissing returns: JsonValue = JsonMissing.of(), + ) : this(parameters, returns, mutableMapOf()) + @JsonProperty("parameters") @ExcludeMissing fun _parameters(): JsonValue = parameters @JsonProperty("returns") @ExcludeMissing fun _returns(): JsonValue = returns + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): FunctionSchema = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -3004,7 +3077,17 @@ private constructor( * Further updates to this [Builder] will not mutate the returned instance. */ fun build(): FunctionSchema = - FunctionSchema(parameters, returns, additionalProperties.toImmutable()) + FunctionSchema(parameters, returns, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): FunctionSchema = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { @@ -3141,27 +3224,20 @@ private constructor( } /** User-controlled metadata about the prompt */ - @NoAutoDetect class Metadata - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -3205,7 +3281,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { @@ -3225,23 +3311,27 @@ private constructor( override fun toString() = "Metadata{additionalProperties=$additionalProperties}" } - @NoAutoDetect class Origin - @JsonCreator private constructor( - @JsonProperty("object_id") - @ExcludeMissing - private val objectId: JsonField = JsonMissing.of(), - @JsonProperty("object_type") - @ExcludeMissing - private val objectType: JsonField = JsonMissing.of(), - @JsonProperty("internal") - @ExcludeMissing - private val internal_: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val objectId: JsonField, + private val objectType: JsonField, + private val internal_: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("object_id") + @ExcludeMissing + objectId: JsonField = JsonMissing.of(), + @JsonProperty("object_type") + @ExcludeMissing + objectType: JsonField = JsonMissing.of(), + @JsonProperty("internal") + @ExcludeMissing + internal_: JsonField = JsonMissing.of(), + ) : this(objectId, objectType, internal_, mutableMapOf()) + /** * Id of the object the function is originating from * @@ -3290,22 +3380,15 @@ private constructor( */ @JsonProperty("internal") @ExcludeMissing fun _internal_(): JsonField = internal_ + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Origin = apply { - if (validated) { - return@apply - } - - objectId() - objectType() - internal_() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -3427,10 +3510,23 @@ private constructor( checkRequired("objectId", objectId), checkRequired("objectType", objectType), internal_, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Origin = apply { + if (validated) { + return@apply + } + + objectId() + objectType() + internal_() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionCreateParams.kt index f902f77a..e7b6ac47 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionCreateParams.kt @@ -9,14 +9,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.models.CodeBundle.* @@ -31,6 +29,7 @@ import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -196,529 +195,317 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("function_data") - @ExcludeMissing - private val functionData: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("project_id") - @ExcludeMissing - private val projectId: JsonField = JsonMissing.of(), - @JsonProperty("slug") - @ExcludeMissing - private val slug: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("function_schema") - @ExcludeMissing - private val functionSchema: JsonField = JsonMissing.of(), - @JsonProperty("function_type") - @ExcludeMissing - private val functionType: JsonField = JsonMissing.of(), - @JsonProperty("origin") - @ExcludeMissing - private val origin: JsonField = JsonMissing.of(), - @JsonProperty("prompt_data") - @ExcludeMissing - private val promptData: JsonField = JsonMissing.of(), - @JsonProperty("tags") - @ExcludeMissing - private val tags: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + fun toBuilder() = Builder().from(this) - /** - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun functionData(): FunctionData = functionData.getRequired("function_data") + companion object { /** - * Name of the prompt + * Returns a mutable builder for constructing an instance of [FunctionCreateParams]. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + * The following fields are required: + * ```java + * .functionData() + * .name() + * .projectId() + * .slug() + * ``` */ - fun name(): String = name.getRequired("name") + @JvmStatic fun builder() = Builder() + } - /** - * Unique identifier for the project that the prompt belongs under - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun projectId(): String = projectId.getRequired("project_id") + /** A builder for [FunctionCreateParams]. */ + class Builder internal constructor() { - /** - * Unique identifier for the prompt - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun slug(): String = slug.getRequired("slug") + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - /** - * Textual description of the prompt - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + @JvmSynthetic + internal fun from(functionCreateParams: FunctionCreateParams) = apply { + body = functionCreateParams.body.toBuilder() + additionalHeaders = functionCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = functionCreateParams.additionalQueryParams.toBuilder() + } + + fun functionData(functionData: FunctionData) = apply { body.functionData(functionData) } /** - * JSON schema for the function's parameters and return type + * Sets [Builder.functionData] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.functionData] with a well-typed [FunctionData] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun functionSchema(): Optional = - Optional.ofNullable(functionSchema.getNullable("function_schema")) + fun functionData(functionData: JsonField) = apply { + body.functionData(functionData) + } - /** - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun functionType(): Optional = - Optional.ofNullable(functionType.getNullable("function_type")) + /** Alias for calling [functionData] with `FunctionData.ofPrompt(prompt)`. */ + fun functionData(prompt: FunctionData.Prompt) = apply { body.functionData(prompt) } - /** - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun origin(): Optional = Optional.ofNullable(origin.getNullable("origin")) + /** Alias for calling [functionData] with `FunctionData.ofCode(code)`. */ + fun functionData(code: FunctionData.Code) = apply { body.functionData(code) } - /** - * The prompt, model, and its parameters - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun promptData(): Optional = - Optional.ofNullable(promptData.getNullable("prompt_data")) + /** Alias for calling [functionData] with `FunctionData.ofGlobal(global)`. */ + fun functionData(global: FunctionData.Global) = apply { body.functionData(global) } + + /** Name of the prompt */ + fun name(name: String) = apply { body.name(name) } /** - * A list of tags for the prompt + * Sets [Builder.name] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) + fun name(name: JsonField) = apply { body.name(name) } + + /** Unique identifier for the project that the prompt belongs under */ + fun projectId(projectId: String) = apply { body.projectId(projectId) } /** - * Returns the raw JSON value of [functionData]. + * Sets [Builder.projectId] to an arbitrary JSON value. * - * Unlike [functionData], this method doesn't throw if the JSON field has an unexpected - * type. + * You should usually call [Builder.projectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("function_data") - @ExcludeMissing - fun _functionData(): JsonField = functionData + fun projectId(projectId: JsonField) = apply { body.projectId(projectId) } + + /** Unique identifier for the prompt */ + fun slug(slug: String) = apply { body.slug(slug) } /** - * Returns the raw JSON value of [name]. + * Sets [Builder.slug] to an arbitrary JSON value. * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.slug] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + fun slug(slug: JsonField) = apply { body.slug(slug) } + + /** Textual description of the prompt */ + fun description(description: String?) = apply { body.description(description) } + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) /** - * Returns the raw JSON value of [projectId]. + * Sets [Builder.description] to an arbitrary JSON value. * - * Unlike [projectId], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("project_id") @ExcludeMissing fun _projectId(): JsonField = projectId + fun description(description: JsonField) = apply { body.description(description) } + + /** JSON schema for the function's parameters and return type */ + fun functionSchema(functionSchema: FunctionSchema?) = apply { + body.functionSchema(functionSchema) + } + + /** Alias for calling [Builder.functionSchema] with `functionSchema.orElse(null)`. */ + fun functionSchema(functionSchema: Optional) = + functionSchema(functionSchema.getOrNull()) /** - * Returns the raw JSON value of [slug]. + * Sets [Builder.functionSchema] to an arbitrary JSON value. * - * Unlike [slug], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.functionSchema] with a well-typed [FunctionSchema] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("slug") @ExcludeMissing fun _slug(): JsonField = slug + fun functionSchema(functionSchema: JsonField) = apply { + body.functionSchema(functionSchema) + } + + fun functionType(functionType: FunctionType?) = apply { body.functionType(functionType) } + + /** Alias for calling [Builder.functionType] with `functionType.orElse(null)`. */ + fun functionType(functionType: Optional) = + functionType(functionType.getOrNull()) /** - * Returns the raw JSON value of [description]. + * Sets [Builder.functionType] to an arbitrary JSON value. * - * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.functionType] with a well-typed [FunctionType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("description") - @ExcludeMissing - fun _description(): JsonField = description + fun functionType(functionType: JsonField) = apply { + body.functionType(functionType) + } + + fun origin(origin: Origin?) = apply { body.origin(origin) } + + /** Alias for calling [Builder.origin] with `origin.orElse(null)`. */ + fun origin(origin: Optional) = origin(origin.getOrNull()) /** - * Returns the raw JSON value of [functionSchema]. + * Sets [Builder.origin] to an arbitrary JSON value. * - * Unlike [functionSchema], this method doesn't throw if the JSON field has an unexpected - * type. + * You should usually call [Builder.origin] with a well-typed [Origin] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("function_schema") - @ExcludeMissing - fun _functionSchema(): JsonField = functionSchema + fun origin(origin: JsonField) = apply { body.origin(origin) } + + /** The prompt, model, and its parameters */ + fun promptData(promptData: PromptData?) = apply { body.promptData(promptData) } + + /** Alias for calling [Builder.promptData] with `promptData.orElse(null)`. */ + fun promptData(promptData: Optional) = promptData(promptData.getOrNull()) /** - * Returns the raw JSON value of [functionType]. + * Sets [Builder.promptData] to an arbitrary JSON value. * - * Unlike [functionType], this method doesn't throw if the JSON field has an unexpected - * type. + * You should usually call [Builder.promptData] with a well-typed [PromptData] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("function_type") - @ExcludeMissing - fun _functionType(): JsonField = functionType + fun promptData(promptData: JsonField) = apply { body.promptData(promptData) } + + /** A list of tags for the prompt */ + fun tags(tags: List?) = apply { body.tags(tags) } + + /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ + fun tags(tags: Optional>) = tags(tags.getOrNull()) /** - * Returns the raw JSON value of [origin]. + * Sets [Builder.tags] to an arbitrary JSON value. * - * Unlike [origin], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.tags] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("origin") @ExcludeMissing fun _origin(): JsonField = origin + fun tags(tags: JsonField>) = apply { body.tags(tags) } /** - * Returns the raw JSON value of [promptData]. + * Adds a single [String] to [tags]. * - * Unlike [promptData], this method doesn't throw if the JSON field has an unexpected type. + * @throws IllegalStateException if the field was previously set to a non-list. */ - @JsonProperty("prompt_data") - @ExcludeMissing - fun _promptData(): JsonField = promptData - - /** - * Returns the raw JSON value of [tags]. - * - * Unlike [tags], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } + fun addTag(tag: String) = apply { body.addTag(tag) } - functionData().validate() - name() - projectId() - slug() - description() - functionSchema().ifPresent { it.validate() } - functionType() - origin().ifPresent { it.validate() } - promptData().ifPresent { it.validate() } - tags() - validated = true + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) } - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .functionData() - * .name() - * .projectId() - * .slug() - * ``` - */ - @JvmStatic fun builder() = Builder() + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) } - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var functionData: JsonField? = null - private var name: JsonField? = null - private var projectId: JsonField? = null - private var slug: JsonField? = null - private var description: JsonField = JsonMissing.of() - private var functionSchema: JsonField = JsonMissing.of() - private var functionType: JsonField = JsonMissing.of() - private var origin: JsonField = JsonMissing.of() - private var promptData: JsonField = JsonMissing.of() - private var tags: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - functionData = body.functionData - name = body.name - projectId = body.projectId - slug = body.slug - description = body.description - functionSchema = body.functionSchema - functionType = body.functionType - origin = body.origin - promptData = body.promptData - tags = body.tags.map { it.toMutableList() } - additionalProperties = body.additionalProperties.toMutableMap() - } - - fun functionData(functionData: FunctionData) = functionData(JsonField.of(functionData)) - - /** - * Sets [Builder.functionData] to an arbitrary JSON value. - * - * You should usually call [Builder.functionData] with a well-typed [FunctionData] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun functionData(functionData: JsonField) = apply { - this.functionData = functionData - } - - /** Alias for calling [functionData] with `FunctionData.ofPrompt(prompt)`. */ - fun functionData(prompt: FunctionData.Prompt) = - functionData(FunctionData.ofPrompt(prompt)) - - /** Alias for calling [functionData] with `FunctionData.ofCode(code)`. */ - fun functionData(code: FunctionData.Code) = functionData(FunctionData.ofCode(code)) - - /** Alias for calling [functionData] with `FunctionData.ofGlobal(global)`. */ - fun functionData(global: FunctionData.Global) = - functionData(FunctionData.ofGlobal(global)) - - /** Name of the prompt */ - fun name(name: String) = name(JsonField.of(name)) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } - - /** Unique identifier for the project that the prompt belongs under */ - fun projectId(projectId: String) = projectId(JsonField.of(projectId)) - - /** - * Sets [Builder.projectId] to an arbitrary JSON value. - * - * You should usually call [Builder.projectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun projectId(projectId: JsonField) = apply { this.projectId = projectId } - - /** Unique identifier for the prompt */ - fun slug(slug: String) = slug(JsonField.of(slug)) - - /** - * Sets [Builder.slug] to an arbitrary JSON value. - * - * You should usually call [Builder.slug] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun slug(slug: JsonField) = apply { this.slug = slug } - - /** Textual description of the prompt */ - fun description(description: String?) = description(JsonField.ofNullable(description)) - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) - - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun description(description: JsonField) = apply { - this.description = description - } - - /** JSON schema for the function's parameters and return type */ - fun functionSchema(functionSchema: FunctionSchema?) = - functionSchema(JsonField.ofNullable(functionSchema)) - - /** Alias for calling [Builder.functionSchema] with `functionSchema.orElse(null)`. */ - fun functionSchema(functionSchema: Optional) = - functionSchema(functionSchema.getOrNull()) - - /** - * Sets [Builder.functionSchema] to an arbitrary JSON value. - * - * You should usually call [Builder.functionSchema] with a well-typed [FunctionSchema] - * value instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun functionSchema(functionSchema: JsonField) = apply { - this.functionSchema = functionSchema + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) } - fun functionType(functionType: FunctionType?) = - functionType(JsonField.ofNullable(functionType)) + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - /** Alias for calling [Builder.functionType] with `functionType.orElse(null)`. */ - fun functionType(functionType: Optional) = - functionType(functionType.getOrNull()) + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } - /** - * Sets [Builder.functionType] to an arbitrary JSON value. - * - * You should usually call [Builder.functionType] with a well-typed [FunctionType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun functionType(functionType: JsonField) = apply { - this.functionType = functionType - } + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - fun origin(origin: Origin?) = origin(JsonField.ofNullable(origin)) + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** Alias for calling [Builder.origin] with `origin.orElse(null)`. */ - fun origin(origin: Optional) = origin(origin.getOrNull()) + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } - /** - * Sets [Builder.origin] to an arbitrary JSON value. - * - * You should usually call [Builder.origin] with a well-typed [Origin] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun origin(origin: JsonField) = apply { this.origin = origin } + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - /** The prompt, model, and its parameters */ - fun promptData(promptData: PromptData?) = promptData(JsonField.ofNullable(promptData)) + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** Alias for calling [Builder.promptData] with `promptData.orElse(null)`. */ - fun promptData(promptData: Optional) = promptData(promptData.getOrNull()) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** - * Sets [Builder.promptData] to an arbitrary JSON value. - * - * You should usually call [Builder.promptData] with a well-typed [PromptData] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun promptData(promptData: JsonField) = apply { - this.promptData = promptData - } + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - /** A list of tags for the prompt */ - fun tags(tags: List?) = tags(JsonField.ofNullable(tags)) + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ - fun tags(tags: Optional>) = tags(tags.getOrNull()) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Sets [Builder.tags] to an arbitrary JSON value. - * - * You should usually call [Builder.tags] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun tags(tags: JsonField>) = apply { - this.tags = tags.map { it.toMutableList() } - } + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Adds a single [String] to [tags]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addTag(tag: String) = apply { - tags = - (tags ?: JsonField.of(mutableListOf())).also { checkKnown("tags", it).add(tag) } - } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .functionData() - * .name() - * .projectId() - * .slug() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("functionData", functionData), - checkRequired("name", name), - checkRequired("projectId", projectId), - checkRequired("slug", slug), - description, - functionSchema, - functionType, - origin, - promptData, - (tags ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), - ) + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - return /* spotless:off */ other is Body && functionData == other.functionData && name == other.name && projectId == other.projectId && slug == other.slug && description == other.description && functionSchema == other.functionSchema && functionType == other.functionType && origin == other.origin && promptData == other.promptData && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(functionData, name, projectId, slug, description, functionSchema, functionType, origin, promptData, tags, additionalProperties) } - /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } - override fun hashCode(): Int = hashCode + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - override fun toString() = - "Body{functionData=$functionData, name=$name, projectId=$projectId, slug=$slug, description=$description, functionSchema=$functionSchema, functionType=$functionType, origin=$origin, promptData=$promptData, tags=$tags, additionalProperties=$additionalProperties}" - } + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - fun toBuilder() = Builder().from(this) + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - companion object { + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } /** - * Returns a mutable builder for constructing an instance of [FunctionCreateParams]. + * Returns an immutable instance of [FunctionCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java @@ -727,321 +514,553 @@ private constructor( * .projectId() * .slug() * ``` + * + * @throws IllegalStateException if any required field is unset. */ - @JvmStatic fun builder() = Builder() + fun build(): FunctionCreateParams = + FunctionCreateParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) } - /** A builder for [FunctionCreateParams]. */ - @NoAutoDetect - class Builder internal constructor() { + @JvmSynthetic internal fun _body(): Body = body - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun from(functionCreateParams: FunctionCreateParams) = apply { - body = functionCreateParams.body.toBuilder() - additionalHeaders = functionCreateParams.additionalHeaders.toBuilder() - additionalQueryParams = functionCreateParams.additionalQueryParams.toBuilder() - } + override fun _queryParams(): QueryParams = additionalQueryParams - fun functionData(functionData: FunctionData) = apply { body.functionData(functionData) } + class Body + private constructor( + private val functionData: JsonField, + private val name: JsonField, + private val projectId: JsonField, + private val slug: JsonField, + private val description: JsonField, + private val functionSchema: JsonField, + private val functionType: JsonField, + private val origin: JsonField, + private val promptData: JsonField, + private val tags: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("function_data") + @ExcludeMissing + functionData: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("slug") @ExcludeMissing slug: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("function_schema") + @ExcludeMissing + functionSchema: JsonField = JsonMissing.of(), + @JsonProperty("function_type") + @ExcludeMissing + functionType: JsonField = JsonMissing.of(), + @JsonProperty("origin") @ExcludeMissing origin: JsonField = JsonMissing.of(), + @JsonProperty("prompt_data") + @ExcludeMissing + promptData: JsonField = JsonMissing.of(), + @JsonProperty("tags") @ExcludeMissing tags: JsonField> = JsonMissing.of(), + ) : this( + functionData, + name, + projectId, + slug, + description, + functionSchema, + functionType, + origin, + promptData, + tags, + mutableMapOf(), + ) /** - * Sets [Builder.functionData] to an arbitrary JSON value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun functionData(): FunctionData = functionData.getRequired("function_data") + + /** + * Name of the prompt * - * You should usually call [Builder.functionData] with a well-typed [FunctionData] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun functionData(functionData: JsonField) = apply { - body.functionData(functionData) - } + fun name(): String = name.getRequired("name") - /** Alias for calling [functionData] with `FunctionData.ofPrompt(prompt)`. */ - fun functionData(prompt: FunctionData.Prompt) = apply { body.functionData(prompt) } + /** + * Unique identifier for the project that the prompt belongs under + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun projectId(): String = projectId.getRequired("project_id") - /** Alias for calling [functionData] with `FunctionData.ofCode(code)`. */ - fun functionData(code: FunctionData.Code) = apply { body.functionData(code) } + /** + * Unique identifier for the prompt + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun slug(): String = slug.getRequired("slug") - /** Alias for calling [functionData] with `FunctionData.ofGlobal(global)`. */ - fun functionData(global: FunctionData.Global) = apply { body.functionData(global) } + /** + * Textual description of the prompt + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun description(): Optional = + Optional.ofNullable(description.getNullable("description")) - /** Name of the prompt */ - fun name(name: String) = apply { body.name(name) } + /** + * JSON schema for the function's parameters and return type + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun functionSchema(): Optional = + Optional.ofNullable(functionSchema.getNullable("function_schema")) /** - * Sets [Builder.name] to an arbitrary JSON value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun functionType(): Optional = + Optional.ofNullable(functionType.getNullable("function_type")) + + /** + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun origin(): Optional = Optional.ofNullable(origin.getNullable("origin")) + + /** + * The prompt, model, and its parameters * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun name(name: JsonField) = apply { body.name(name) } + fun promptData(): Optional = + Optional.ofNullable(promptData.getNullable("prompt_data")) - /** Unique identifier for the project that the prompt belongs under */ - fun projectId(projectId: String) = apply { body.projectId(projectId) } + /** + * A list of tags for the prompt + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) /** - * Sets [Builder.projectId] to an arbitrary JSON value. + * Returns the raw JSON value of [functionData]. * - * You should usually call [Builder.projectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [functionData], this method doesn't throw if the JSON field has an unexpected + * type. */ - fun projectId(projectId: JsonField) = apply { body.projectId(projectId) } + @JsonProperty("function_data") + @ExcludeMissing + fun _functionData(): JsonField = functionData - /** Unique identifier for the prompt */ - fun slug(slug: String) = apply { body.slug(slug) } + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [projectId]. + * + * Unlike [projectId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("project_id") @ExcludeMissing fun _projectId(): JsonField = projectId + + /** + * Returns the raw JSON value of [slug]. + * + * Unlike [slug], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("slug") @ExcludeMissing fun _slug(): JsonField = slug + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [functionSchema]. + * + * Unlike [functionSchema], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("function_schema") + @ExcludeMissing + fun _functionSchema(): JsonField = functionSchema + + /** + * Returns the raw JSON value of [functionType]. + * + * Unlike [functionType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("function_type") + @ExcludeMissing + fun _functionType(): JsonField = functionType + + /** + * Returns the raw JSON value of [origin]. + * + * Unlike [origin], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("origin") @ExcludeMissing fun _origin(): JsonField = origin /** - * Sets [Builder.slug] to an arbitrary JSON value. + * Returns the raw JSON value of [promptData]. * - * You should usually call [Builder.slug] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [promptData], this method doesn't throw if the JSON field has an unexpected type. */ - fun slug(slug: JsonField) = apply { body.slug(slug) } - - /** Textual description of the prompt */ - fun description(description: String?) = apply { body.description(description) } - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) + @JsonProperty("prompt_data") + @ExcludeMissing + fun _promptData(): JsonField = promptData /** - * Sets [Builder.description] to an arbitrary JSON value. + * Returns the raw JSON value of [tags]. * - * You should usually call [Builder.description] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [tags], this method doesn't throw if the JSON field has an unexpected type. */ - fun description(description: JsonField) = apply { body.description(description) } + @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags - /** JSON schema for the function's parameters and return type */ - fun functionSchema(functionSchema: FunctionSchema?) = apply { - body.functionSchema(functionSchema) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - /** Alias for calling [Builder.functionSchema] with `functionSchema.orElse(null)`. */ - fun functionSchema(functionSchema: Optional) = - functionSchema(functionSchema.getOrNull()) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - /** - * Sets [Builder.functionSchema] to an arbitrary JSON value. - * - * You should usually call [Builder.functionSchema] with a well-typed [FunctionSchema] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun functionSchema(functionSchema: JsonField) = apply { - body.functionSchema(functionSchema) + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .functionData() + * .name() + * .projectId() + * .slug() + * ``` + */ + @JvmStatic fun builder() = Builder() } - fun functionType(functionType: FunctionType?) = apply { body.functionType(functionType) } + /** A builder for [Body]. */ + class Builder internal constructor() { - /** Alias for calling [Builder.functionType] with `functionType.orElse(null)`. */ - fun functionType(functionType: Optional) = - functionType(functionType.getOrNull()) + private var functionData: JsonField? = null + private var name: JsonField? = null + private var projectId: JsonField? = null + private var slug: JsonField? = null + private var description: JsonField = JsonMissing.of() + private var functionSchema: JsonField = JsonMissing.of() + private var functionType: JsonField = JsonMissing.of() + private var origin: JsonField = JsonMissing.of() + private var promptData: JsonField = JsonMissing.of() + private var tags: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() - /** - * Sets [Builder.functionType] to an arbitrary JSON value. - * - * You should usually call [Builder.functionType] with a well-typed [FunctionType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun functionType(functionType: JsonField) = apply { - body.functionType(functionType) - } + @JvmSynthetic + internal fun from(body: Body) = apply { + functionData = body.functionData + name = body.name + projectId = body.projectId + slug = body.slug + description = body.description + functionSchema = body.functionSchema + functionType = body.functionType + origin = body.origin + promptData = body.promptData + tags = body.tags.map { it.toMutableList() } + additionalProperties = body.additionalProperties.toMutableMap() + } - fun origin(origin: Origin?) = apply { body.origin(origin) } + fun functionData(functionData: FunctionData) = functionData(JsonField.of(functionData)) - /** Alias for calling [Builder.origin] with `origin.orElse(null)`. */ - fun origin(origin: Optional) = origin(origin.getOrNull()) + /** + * Sets [Builder.functionData] to an arbitrary JSON value. + * + * You should usually call [Builder.functionData] with a well-typed [FunctionData] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun functionData(functionData: JsonField) = apply { + this.functionData = functionData + } - /** - * Sets [Builder.origin] to an arbitrary JSON value. - * - * You should usually call [Builder.origin] with a well-typed [Origin] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun origin(origin: JsonField) = apply { body.origin(origin) } + /** Alias for calling [functionData] with `FunctionData.ofPrompt(prompt)`. */ + fun functionData(prompt: FunctionData.Prompt) = + functionData(FunctionData.ofPrompt(prompt)) - /** The prompt, model, and its parameters */ - fun promptData(promptData: PromptData?) = apply { body.promptData(promptData) } + /** Alias for calling [functionData] with `FunctionData.ofCode(code)`. */ + fun functionData(code: FunctionData.Code) = functionData(FunctionData.ofCode(code)) - /** Alias for calling [Builder.promptData] with `promptData.orElse(null)`. */ - fun promptData(promptData: Optional) = promptData(promptData.getOrNull()) + /** Alias for calling [functionData] with `FunctionData.ofGlobal(global)`. */ + fun functionData(global: FunctionData.Global) = + functionData(FunctionData.ofGlobal(global)) - /** - * Sets [Builder.promptData] to an arbitrary JSON value. - * - * You should usually call [Builder.promptData] with a well-typed [PromptData] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun promptData(promptData: JsonField) = apply { body.promptData(promptData) } + /** Name of the prompt */ + fun name(name: String) = name(JsonField.of(name)) - /** A list of tags for the prompt */ - fun tags(tags: List?) = apply { body.tags(tags) } + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } - /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ - fun tags(tags: Optional>) = tags(tags.getOrNull()) + /** Unique identifier for the project that the prompt belongs under */ + fun projectId(projectId: String) = projectId(JsonField.of(projectId)) - /** - * Sets [Builder.tags] to an arbitrary JSON value. - * - * You should usually call [Builder.tags] with a well-typed `List` value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun tags(tags: JsonField>) = apply { body.tags(tags) } + /** + * Sets [Builder.projectId] to an arbitrary JSON value. + * + * You should usually call [Builder.projectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun projectId(projectId: JsonField) = apply { this.projectId = projectId } - /** - * Adds a single [String] to [tags]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addTag(tag: String) = apply { body.addTag(tag) } + /** Unique identifier for the prompt */ + fun slug(slug: String) = slug(JsonField.of(slug)) - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) - } + /** + * Sets [Builder.slug] to an arbitrary JSON value. + * + * You should usually call [Builder.slug] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun slug(slug: JsonField) = apply { this.slug = slug } - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } + /** Textual description of the prompt */ + fun description(description: String?) = description(JsonField.ofNullable(description)) - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun description(description: JsonField) = apply { + this.description = description } - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + /** JSON schema for the function's parameters and return type */ + fun functionSchema(functionSchema: FunctionSchema?) = + functionSchema(JsonField.ofNullable(functionSchema)) - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } + /** Alias for calling [Builder.functionSchema] with `functionSchema.orElse(null)`. */ + fun functionSchema(functionSchema: Optional) = + functionSchema(functionSchema.getOrNull()) - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * Sets [Builder.functionSchema] to an arbitrary JSON value. + * + * You should usually call [Builder.functionSchema] with a well-typed [FunctionSchema] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun functionSchema(functionSchema: JsonField) = apply { + this.functionSchema = functionSchema + } - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + fun functionType(functionType: FunctionType?) = + functionType(JsonField.ofNullable(functionType)) - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } + /** Alias for calling [Builder.functionType] with `functionType.orElse(null)`. */ + fun functionType(functionType: Optional) = + functionType(functionType.getOrNull()) + + /** + * Sets [Builder.functionType] to an arbitrary JSON value. + * + * You should usually call [Builder.functionType] with a well-typed [FunctionType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun functionType(functionType: JsonField) = apply { + this.functionType = functionType + } - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } + fun origin(origin: Origin?) = origin(JsonField.ofNullable(origin)) - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** Alias for calling [Builder.origin] with `origin.orElse(null)`. */ + fun origin(origin: Optional) = origin(origin.getOrNull()) - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** + * Sets [Builder.origin] to an arbitrary JSON value. + * + * You should usually call [Builder.origin] with a well-typed [Origin] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun origin(origin: JsonField) = apply { this.origin = origin } - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } + /** The prompt, model, and its parameters */ + fun promptData(promptData: PromptData?) = promptData(JsonField.ofNullable(promptData)) - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } + /** Alias for calling [Builder.promptData] with `promptData.orElse(null)`. */ + fun promptData(promptData: Optional) = promptData(promptData.getOrNull()) - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** + * Sets [Builder.promptData] to an arbitrary JSON value. + * + * You should usually call [Builder.promptData] with a well-typed [PromptData] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun promptData(promptData: JsonField) = apply { + this.promptData = promptData + } - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** A list of tags for the prompt */ + fun tags(tags: List?) = tags(JsonField.ofNullable(tags)) - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ + fun tags(tags: Optional>) = tags(tags.getOrNull()) - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } + /** + * Sets [Builder.tags] to an arbitrary JSON value. + * + * You should usually call [Builder.tags] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tags(tags: JsonField>) = apply { + this.tags = tags.map { it.toMutableList() } + } - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + /** + * Adds a single [String] to [tags]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTag(tag: String) = apply { + tags = + (tags ?: JsonField.of(mutableListOf())).also { checkKnown("tags", it).add(tag) } + } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .functionData() + * .name() + * .projectId() + * .slug() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("functionData", functionData), + checkRequired("name", name), + checkRequired("projectId", projectId), + checkRequired("slug", slug), + description, + functionSchema, + functionType, + origin, + promptData, + (tags ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } + private var validated: Boolean = false - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + fun validate(): Body = apply { + if (validated) { + return@apply + } + + functionData().validate() + name() + projectId() + slug() + description() + functionSchema().ifPresent { it.validate() } + functionType() + origin().ifPresent { it.validate() } + promptData().ifPresent { it.validate() } + tags() + validated = true } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) + return /* spotless:off */ other is Body && functionData == other.functionData && name == other.name && projectId == other.projectId && slug == other.slug && description == other.description && functionSchema == other.functionSchema && functionType == other.functionType && origin == other.origin && promptData == other.promptData && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ } - /** - * Returns an immutable instance of [FunctionCreateParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .functionData() - * .name() - * .projectId() - * .slug() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): FunctionCreateParams = - FunctionCreateParams( - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(functionData, name, projectId, slug, description, functionSchema, functionType, origin, promptData, tags, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{functionData=$functionData, name=$name, projectId=$projectId, slug=$slug, description=$description, functionSchema=$functionSchema, functionType=$functionType, origin=$origin, promptData=$promptData, tags=$tags, additionalProperties=$additionalProperties}" } @JsonDeserialize(using = FunctionData.Deserializer::class) @@ -1202,17 +1221,17 @@ private constructor( } } - @NoAutoDetect class Prompt - @JsonCreator private constructor( - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of() + ) : this(type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -1227,20 +1246,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Prompt = apply { - if (validated) { - return@apply - } - - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1315,7 +1329,18 @@ private constructor( * @throws IllegalStateException if any required field is unset. */ fun build(): Prompt = - Prompt(checkRequired("type", type), additionalProperties.toImmutable()) + Prompt(checkRequired("type", type), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Prompt = apply { + if (validated) { + return@apply + } + + type() + validated = true } class Type @JsonCreator private constructor(private val value: JsonField) : @@ -1433,20 +1458,19 @@ private constructor( "Prompt{type=$type, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Code - @JsonCreator private constructor( - @JsonProperty("data") - @ExcludeMissing - private val data: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val data: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(data, type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -1475,21 +1499,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Code = apply { - if (validated) { - return@apply - } - - data().validate() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1588,10 +1606,22 @@ private constructor( Code( checkRequired("data", data), checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Code = apply { + if (validated) { + return@apply + } + + data().validate() + type() + validated = true + } + @JsonDeserialize(using = Data.Deserializer::class) @JsonSerialize(using = Data.Serializer::class) class Data @@ -1728,30 +1758,43 @@ private constructor( } } - @NoAutoDetect class Bundle - @JsonCreator private constructor( - @JsonProperty("bundle_id") - @ExcludeMissing - private val bundleId: JsonField = JsonMissing.of(), - @JsonProperty("location") - @ExcludeMissing - private val location: JsonField = JsonMissing.of(), - @JsonProperty("runtime_context") - @ExcludeMissing - private val runtimeContext: JsonField = - JsonMissing.of(), - @JsonProperty("preview") - @ExcludeMissing - private val preview: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val bundleId: JsonField, + private val location: JsonField, + private val runtimeContext: JsonField, + private val preview: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("bundle_id") + @ExcludeMissing + bundleId: JsonField = JsonMissing.of(), + @JsonProperty("location") + @ExcludeMissing + location: JsonField = JsonMissing.of(), + @JsonProperty("runtime_context") + @ExcludeMissing + runtimeContext: JsonField = JsonMissing.of(), + @JsonProperty("preview") + @ExcludeMissing + preview: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + ) : this(bundleId, location, runtimeContext, preview, type, mutableMapOf()) + + fun toCodeBundle(): CodeBundle = + CodeBundle.builder() + .bundleId(bundleId) + .location(location) + .runtimeContext(runtimeContext) + .preview(preview) + .build() + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type or is unexpectedly missing or null (e.g. if the server responded with @@ -1838,32 +1881,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun toCodeBundle(): CodeBundle = - CodeBundle.builder() - .bundleId(bundleId) - .location(location) - .runtimeContext(runtimeContext) - .preview(preview) - .build() - - private var validated: Boolean = false - - fun validate(): Bundle = apply { - if (validated) { - return@apply - } - - bundleId() - location().validate() - runtimeContext().validate() - preview() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -2030,10 +2056,25 @@ private constructor( checkRequired("runtimeContext", runtimeContext), preview, checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Bundle = apply { + if (validated) { + return@apply + } + + bundleId() + location().validate() + runtimeContext().validate() + preview() + type() + validated = true + } + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2153,23 +2194,27 @@ private constructor( "Bundle{bundleId=$bundleId, location=$location, runtimeContext=$runtimeContext, preview=$preview, type=$type, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Inline - @JsonCreator private constructor( - @JsonProperty("code") - @ExcludeMissing - private val code: JsonField = JsonMissing.of(), - @JsonProperty("runtime_context") - @ExcludeMissing - private val runtimeContext: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val code: JsonField, + private val runtimeContext: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("code") + @ExcludeMissing + code: JsonField = JsonMissing.of(), + @JsonProperty("runtime_context") + @ExcludeMissing + runtimeContext: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + ) : this(code, runtimeContext, type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type or is unexpectedly missing or null (e.g. if the server responded with @@ -2218,22 +2263,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Inline = apply { - if (validated) { - return@apply - } - - code() - runtimeContext().validate() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -2346,25 +2384,40 @@ private constructor( checkRequired("code", code), checkRequired("runtimeContext", runtimeContext), checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } - @NoAutoDetect + private var validated: Boolean = false + + fun validate(): Inline = apply { + if (validated) { + return@apply + } + + code() + runtimeContext().validate() + type() + validated = true + } + class RuntimeContext - @JsonCreator private constructor( - @JsonProperty("runtime") - @ExcludeMissing - private val runtime: JsonField = JsonMissing.of(), - @JsonProperty("version") - @ExcludeMissing - private val version: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = - immutableEmptyMap(), + private val runtime: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("runtime") + @ExcludeMissing + runtime: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + version: JsonField = JsonMissing.of(), + ) : this(runtime, version, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an * unexpected type or is unexpectedly missing or null (e.g. if the server @@ -2399,21 +2452,15 @@ private constructor( @ExcludeMissing fun _version(): JsonField = version + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): RuntimeContext = apply { - if (validated) { - return@apply - } - - runtime() - version() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -2514,10 +2561,22 @@ private constructor( RuntimeContext( checkRequired("runtime", runtime), checkRequired("version", version), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): RuntimeContext = apply { + if (validated) { + return@apply + } + + runtime() + version() + validated = true + } + class Runtime @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2883,20 +2942,19 @@ private constructor( "Code{data=$data, type=$type, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Global - @JsonCreator private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val name: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(name, type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -2925,21 +2983,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Global = apply { - if (validated) { - return@apply - } - - name() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -3032,10 +3084,22 @@ private constructor( Global( checkRequired("name", name), checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Global = apply { + if (validated) { + return@apply + } + + name() + type() + validated = true + } + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -3153,35 +3217,32 @@ private constructor( } /** JSON schema for the function's parameters and return type */ - @NoAutoDetect class FunctionSchema - @JsonCreator private constructor( - @JsonProperty("parameters") - @ExcludeMissing - private val parameters: JsonValue = JsonMissing.of(), - @JsonProperty("returns") @ExcludeMissing private val returns: JsonValue = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val parameters: JsonValue, + private val returns: JsonValue, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("parameters") @ExcludeMissing parameters: JsonValue = JsonMissing.of(), + @JsonProperty("returns") @ExcludeMissing returns: JsonValue = JsonMissing.of(), + ) : this(parameters, returns, mutableMapOf()) + @JsonProperty("parameters") @ExcludeMissing fun _parameters(): JsonValue = parameters @JsonProperty("returns") @ExcludeMissing fun _returns(): JsonValue = returns + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): FunctionSchema = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -3234,7 +3295,17 @@ private constructor( * Further updates to this [Builder] will not mutate the returned instance. */ fun build(): FunctionSchema = - FunctionSchema(parameters, returns, additionalProperties.toImmutable()) + FunctionSchema(parameters, returns, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): FunctionSchema = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { @@ -3370,23 +3441,27 @@ private constructor( override fun toString() = value.toString() } - @NoAutoDetect class Origin - @JsonCreator private constructor( - @JsonProperty("object_id") - @ExcludeMissing - private val objectId: JsonField = JsonMissing.of(), - @JsonProperty("object_type") - @ExcludeMissing - private val objectType: JsonField = JsonMissing.of(), - @JsonProperty("internal") - @ExcludeMissing - private val internal_: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val objectId: JsonField, + private val objectType: JsonField, + private val internal_: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("object_id") + @ExcludeMissing + objectId: JsonField = JsonMissing.of(), + @JsonProperty("object_type") + @ExcludeMissing + objectType: JsonField = JsonMissing.of(), + @JsonProperty("internal") + @ExcludeMissing + internal_: JsonField = JsonMissing.of(), + ) : this(objectId, objectType, internal_, mutableMapOf()) + /** * Id of the object the function is originating from * @@ -3435,22 +3510,15 @@ private constructor( */ @JsonProperty("internal") @ExcludeMissing fun _internal_(): JsonField = internal_ + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Origin = apply { - if (validated) { - return@apply - } - - objectId() - objectType() - internal_() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -3572,10 +3640,23 @@ private constructor( checkRequired("objectId", objectId), checkRequired("objectType", objectType), internal_, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Origin = apply { + if (validated) { + return@apply + } + + objectId() + objectType() + internal_() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionDeleteParams.kt index d9fe23d7..c2e2e81c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionDeleteParams.kt @@ -2,13 +2,15 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.toImmutable +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import java.util.Collections import java.util.Objects import java.util.Optional @@ -18,7 +20,7 @@ private constructor( private val functionId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: Map, + private val additionalBodyProperties: MutableMap, ) : Params { /** Function id */ @@ -28,21 +30,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _additionalBodyProperties(): Map = additionalBodyProperties - - @JvmSynthetic - internal fun _body(): Optional> = - Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - - fun _pathParam(index: Int): String = - when (index) { - 0 -> functionId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders + @JsonAnySetter + private fun putAdditionalBodyProperty(key: String, value: JsonValue) { + additionalBodyProperties.put(key, value) + } - override fun _queryParams(): QueryParams = additionalQueryParams + @JsonAnyGetter + @ExcludeMissing + fun _additionalBodyProperties(): Map = + Collections.unmodifiableMap(additionalBodyProperties) fun toBuilder() = Builder().from(this) @@ -60,7 +56,6 @@ private constructor( } /** A builder for [FunctionDeleteParams]. */ - @NoAutoDetect class Builder internal constructor() { private var functionId: String? = null @@ -216,10 +211,24 @@ private constructor( checkRequired("functionId", functionId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toImmutable(), + additionalBodyProperties.toMutableMap(), ) } + @JvmSynthetic + internal fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> functionId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt index f6a0e50d..439596d8 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt @@ -9,14 +9,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter @@ -30,6 +28,7 @@ import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -149,196 +148,485 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body + fun toBuilder() = Builder().from(this) - fun _pathParam(index: Int): String = - when (index) { - 0 -> functionId - else -> "" - } + companion object { - override fun _headers(): Headers = additionalHeaders + /** + * Returns a mutable builder for constructing an instance of [FunctionInvokeParams]. + * + * The following fields are required: + * ```java + * .functionId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun _queryParams(): QueryParams = additionalQueryParams + /** A builder for [FunctionInvokeParams]. */ + class Builder internal constructor() { - /** The request to invoke a function */ - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("expected") - @ExcludeMissing - private val expected: JsonValue = JsonMissing.of(), - @JsonProperty("input") @ExcludeMissing private val input: JsonValue = JsonMissing.of(), - @JsonProperty("messages") - @ExcludeMissing - private val messages: JsonField> = JsonMissing.of(), - @JsonProperty("metadata") - @ExcludeMissing - private val metadata: JsonField = JsonMissing.of(), - @JsonProperty("mode") @ExcludeMissing private val mode: JsonField = JsonMissing.of(), - @JsonProperty("parent") - @ExcludeMissing - private val parent: JsonField = JsonMissing.of(), - @JsonProperty("stream") - @ExcludeMissing - private val stream: JsonField = JsonMissing.of(), - @JsonProperty("version") - @ExcludeMissing - private val version: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + private var functionId: String? = null + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(functionInvokeParams: FunctionInvokeParams) = apply { + functionId = functionInvokeParams.functionId + body = functionInvokeParams.body.toBuilder() + additionalHeaders = functionInvokeParams.additionalHeaders.toBuilder() + additionalQueryParams = functionInvokeParams.additionalQueryParams.toBuilder() + } + + /** Function id */ + fun functionId(functionId: String) = apply { this.functionId = functionId } /** The expected output of the function */ - @JsonProperty("expected") @ExcludeMissing fun _expected(): JsonValue = expected + fun expected(expected: JsonValue) = apply { body.expected(expected) } /** Argument to the function, which can be any JSON serializable value */ - @JsonProperty("input") @ExcludeMissing fun _input(): JsonValue = input + fun input(input: JsonValue) = apply { body.input(input) } - /** - * If the function is an LLM, additional messages to pass along to it - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun messages(): Optional> = - Optional.ofNullable(messages.getNullable("messages")) + /** If the function is an LLM, additional messages to pass along to it */ + fun messages(messages: List) = apply { body.messages(messages) } /** - * Any relevant metadata + * Sets [Builder.messages] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.messages] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun messages(messages: JsonField>) = apply { body.messages(messages) } /** - * The mode format of the returned value (defaults to 'auto') + * Adds a single [Message] to [messages]. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * @throws IllegalStateException if the field was previously set to a non-list. */ - fun mode(): Optional = Optional.ofNullable(mode.getNullable("mode")) + fun addMessage(message: Message) = apply { body.addMessage(message) } - /** - * Options for tracing the function call - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun parent(): Optional = Optional.ofNullable(parent.getNullable("parent")) + /** Alias for calling [addMessage] with `Message.ofSystem(system)`. */ + fun addMessage(system: Message.System) = apply { body.addMessage(system) } - /** - * Whether to stream the response. If true, results will be returned in the Braintrust SSE - * format. - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun stream(): Optional = Optional.ofNullable(stream.getNullable("stream")) + /** Alias for calling [addMessage] with `Message.ofUser(user)`. */ + fun addMessage(user: Message.User) = apply { body.addMessage(user) } + + /** Alias for calling [addMessage] with `Message.ofAssistant(assistant)`. */ + fun addMessage(assistant: Message.Assistant) = apply { body.addMessage(assistant) } + + /** Alias for calling [addMessage] with `Message.ofTool(tool)`. */ + fun addMessage(tool: Message.Tool) = apply { body.addMessage(tool) } + + /** Alias for calling [addMessage] with `Message.ofFunction(function)`. */ + fun addMessage(function: Message.Function) = apply { body.addMessage(function) } + + /** Alias for calling [addMessage] with `Message.ofFallback(fallback)`. */ + fun addMessage(fallback: Message.Fallback) = apply { body.addMessage(fallback) } + + /** Any relevant metadata */ + fun metadata(metadata: Metadata?) = apply { body.metadata(metadata) } + + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) /** - * The version of the function + * Sets [Builder.metadata] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun version(): Optional = Optional.ofNullable(version.getNullable("version")) + fun metadata(metadata: JsonField) = apply { body.metadata(metadata) } + + /** The mode format of the returned value (defaults to 'auto') */ + fun mode(mode: Mode?) = apply { body.mode(mode) } + + /** Alias for calling [Builder.mode] with `mode.orElse(null)`. */ + fun mode(mode: Optional) = mode(mode.getOrNull()) /** - * Returns the raw JSON value of [messages]. + * Sets [Builder.mode] to an arbitrary JSON value. * - * Unlike [messages], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.mode] with a well-typed [Mode] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("messages") - @ExcludeMissing - fun _messages(): JsonField> = messages + fun mode(mode: JsonField) = apply { body.mode(mode) } + + /** Options for tracing the function call */ + fun parent(parent: Parent) = apply { body.parent(parent) } /** - * Returns the raw JSON value of [metadata]. + * Sets [Builder.parent] to an arbitrary JSON value. * - * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.parent] with a well-typed [Parent] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + fun parent(parent: JsonField) = apply { body.parent(parent) } + + /** Alias for calling [parent] with `Parent.ofSpanParentStruct(spanParentStruct)`. */ + fun parent(spanParentStruct: Parent.SpanParentStruct) = apply { + body.parent(spanParentStruct) + } + + /** Alias for calling [parent] with `Parent.ofString(string)`. */ + fun parent(string: String) = apply { body.parent(string) } /** - * Returns the raw JSON value of [mode]. - * - * Unlike [mode], this method doesn't throw if the JSON field has an unexpected type. + * Whether to stream the response. If true, results will be returned in the Braintrust SSE + * format. */ - @JsonProperty("mode") @ExcludeMissing fun _mode(): JsonField = mode + fun stream(stream: Boolean?) = apply { body.stream(stream) } /** - * Returns the raw JSON value of [parent]. + * Alias for [Builder.stream]. * - * Unlike [parent], this method doesn't throw if the JSON field has an unexpected type. + * This unboxed primitive overload exists for backwards compatibility. */ - @JsonProperty("parent") @ExcludeMissing fun _parent(): JsonField = parent + fun stream(stream: Boolean) = stream(stream as Boolean?) + + /** Alias for calling [Builder.stream] with `stream.orElse(null)`. */ + fun stream(stream: Optional) = stream(stream.getOrNull()) /** - * Returns the raw JSON value of [stream]. + * Sets [Builder.stream] to an arbitrary JSON value. * - * Unlike [stream], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.stream] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("stream") @ExcludeMissing fun _stream(): JsonField = stream + fun stream(stream: JsonField) = apply { body.stream(stream) } + + /** The version of the function */ + fun version(version: String) = apply { body.version(version) } /** - * Returns the raw JSON value of [version]. + * Sets [Builder.version] to an arbitrary JSON value. * - * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.version] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version + fun version(version: JsonField) = apply { body.version(version) } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } - private var validated: Boolean = false + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } - fun validate(): Body = apply { - if (validated) { - return@apply + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) } - messages().ifPresent { it.forEach { it.validate() } } - metadata().ifPresent { it.validate() } - mode() - parent().ifPresent { it.validate() } - stream() - version() - validated = true + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) } - fun toBuilder() = Builder().from(this) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - companion object { + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** Returns a mutable builder for constructing an instance of [Body]. */ - @JvmStatic fun builder() = Builder() + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - /** A builder for [Body]. */ - class Builder internal constructor() { + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - private var expected: JsonValue = JsonMissing.of() - private var input: JsonValue = JsonMissing.of() - private var messages: JsonField>? = null - private var metadata: JsonField = JsonMissing.of() - private var mode: JsonField = JsonMissing.of() - private var parent: JsonField = JsonMissing.of() - private var stream: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - @JvmSynthetic - internal fun from(body: Body) = apply { - expected = body.expected - input = body.input - messages = body.messages.map { it.toMutableList() } - metadata = body.metadata - mode = body.mode - parent = body.parent + 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 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) + } + + /** + * Returns an immutable instance of [FunctionInvokeParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .functionId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): FunctionInvokeParams = + FunctionInvokeParams( + checkRequired("functionId", functionId), + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + @JvmSynthetic internal fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> functionId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + /** The request to invoke a function */ + class Body + private constructor( + private val expected: JsonValue, + private val input: JsonValue, + private val messages: JsonField>, + private val metadata: JsonField, + private val mode: JsonField, + private val parent: JsonField, + private val stream: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("expected") @ExcludeMissing expected: JsonValue = JsonMissing.of(), + @JsonProperty("input") @ExcludeMissing input: JsonValue = JsonMissing.of(), + @JsonProperty("messages") + @ExcludeMissing + messages: JsonField> = JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("mode") @ExcludeMissing mode: JsonField = JsonMissing.of(), + @JsonProperty("parent") @ExcludeMissing parent: JsonField = JsonMissing.of(), + @JsonProperty("stream") @ExcludeMissing stream: JsonField = JsonMissing.of(), + @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), + ) : this(expected, input, messages, metadata, mode, parent, stream, version, mutableMapOf()) + + /** The expected output of the function */ + @JsonProperty("expected") @ExcludeMissing fun _expected(): JsonValue = expected + + /** Argument to the function, which can be any JSON serializable value */ + @JsonProperty("input") @ExcludeMissing fun _input(): JsonValue = input + + /** + * If the function is an LLM, additional messages to pass along to it + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun messages(): Optional> = + Optional.ofNullable(messages.getNullable("messages")) + + /** + * Any relevant metadata + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + + /** + * The mode format of the returned value (defaults to 'auto') + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun mode(): Optional = Optional.ofNullable(mode.getNullable("mode")) + + /** + * Options for tracing the function call + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun parent(): Optional = Optional.ofNullable(parent.getNullable("parent")) + + /** + * Whether to stream the response. If true, results will be returned in the Braintrust SSE + * format. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun stream(): Optional = Optional.ofNullable(stream.getNullable("stream")) + + /** + * The version of the function + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun version(): Optional = Optional.ofNullable(version.getNullable("version")) + + /** + * Returns the raw JSON value of [messages]. + * + * Unlike [messages], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("messages") + @ExcludeMissing + fun _messages(): JsonField> = messages + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [mode]. + * + * Unlike [mode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("mode") @ExcludeMissing fun _mode(): JsonField = mode + + /** + * Returns the raw JSON value of [parent]. + * + * Unlike [parent], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("parent") @ExcludeMissing fun _parent(): JsonField = parent + + /** + * Returns the raw JSON value of [stream]. + * + * Unlike [stream], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("stream") @ExcludeMissing fun _stream(): JsonField = stream + + /** + * Returns the raw JSON value of [version]. + * + * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Body]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var expected: JsonValue = JsonMissing.of() + private var input: JsonValue = JsonMissing.of() + private var messages: JsonField>? = null + private var metadata: JsonField = JsonMissing.of() + private var mode: JsonField = JsonMissing.of() + private var parent: JsonField = JsonMissing.of() + private var stream: JsonField = JsonMissing.of() + private var version: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + expected = body.expected + input = body.input + messages = body.messages.map { it.toMutableList() } + metadata = body.metadata + mode = body.mode + parent = body.parent stream = body.stream version = body.version additionalProperties = body.additionalProperties.toMutableMap() @@ -483,357 +771,74 @@ private constructor( fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - 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) - } - - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Body = - Body( - expected, - input, - (messages ?: JsonMissing.of()).map { it.toImmutable() }, - metadata, - mode, - parent, - stream, - version, - additionalProperties.toImmutable(), - ) - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Body && expected == other.expected && input == other.input && messages == other.messages && metadata == other.metadata && mode == other.mode && parent == other.parent && stream == other.stream && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(expected, input, messages, metadata, mode, parent, stream, version, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Body{expected=$expected, input=$input, messages=$messages, metadata=$metadata, mode=$mode, parent=$parent, stream=$stream, version=$version, additionalProperties=$additionalProperties}" - } - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [FunctionInvokeParams]. - * - * The following fields are required: - * ```java - * .functionId() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [FunctionInvokeParams]. */ - @NoAutoDetect - class Builder internal constructor() { - - private var functionId: String? = null - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - - @JvmSynthetic - internal fun from(functionInvokeParams: FunctionInvokeParams) = apply { - functionId = functionInvokeParams.functionId - body = functionInvokeParams.body.toBuilder() - additionalHeaders = functionInvokeParams.additionalHeaders.toBuilder() - additionalQueryParams = functionInvokeParams.additionalQueryParams.toBuilder() - } - - /** Function id */ - fun functionId(functionId: String) = apply { this.functionId = functionId } - - /** The expected output of the function */ - fun expected(expected: JsonValue) = apply { body.expected(expected) } - - /** Argument to the function, which can be any JSON serializable value */ - fun input(input: JsonValue) = apply { body.input(input) } - - /** If the function is an LLM, additional messages to pass along to it */ - fun messages(messages: List) = apply { body.messages(messages) } - - /** - * Sets [Builder.messages] to an arbitrary JSON value. - * - * You should usually call [Builder.messages] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun messages(messages: JsonField>) = apply { body.messages(messages) } - - /** - * Adds a single [Message] to [messages]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addMessage(message: Message) = apply { body.addMessage(message) } - - /** Alias for calling [addMessage] with `Message.ofSystem(system)`. */ - fun addMessage(system: Message.System) = apply { body.addMessage(system) } - - /** Alias for calling [addMessage] with `Message.ofUser(user)`. */ - fun addMessage(user: Message.User) = apply { body.addMessage(user) } - - /** Alias for calling [addMessage] with `Message.ofAssistant(assistant)`. */ - fun addMessage(assistant: Message.Assistant) = apply { body.addMessage(assistant) } - - /** Alias for calling [addMessage] with `Message.ofTool(tool)`. */ - fun addMessage(tool: Message.Tool) = apply { body.addMessage(tool) } - - /** Alias for calling [addMessage] with `Message.ofFunction(function)`. */ - fun addMessage(function: Message.Function) = apply { body.addMessage(function) } - - /** Alias for calling [addMessage] with `Message.ofFallback(fallback)`. */ - fun addMessage(fallback: Message.Fallback) = apply { body.addMessage(fallback) } - - /** Any relevant metadata */ - fun metadata(metadata: Metadata?) = apply { body.metadata(metadata) } - - /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ - fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) - - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun metadata(metadata: JsonField) = apply { body.metadata(metadata) } - - /** The mode format of the returned value (defaults to 'auto') */ - fun mode(mode: Mode?) = apply { body.mode(mode) } - - /** Alias for calling [Builder.mode] with `mode.orElse(null)`. */ - fun mode(mode: Optional) = mode(mode.getOrNull()) - - /** - * Sets [Builder.mode] to an arbitrary JSON value. - * - * You should usually call [Builder.mode] with a well-typed [Mode] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun mode(mode: JsonField) = apply { body.mode(mode) } - - /** Options for tracing the function call */ - fun parent(parent: Parent) = apply { body.parent(parent) } - - /** - * Sets [Builder.parent] to an arbitrary JSON value. - * - * You should usually call [Builder.parent] with a well-typed [Parent] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun parent(parent: JsonField) = apply { body.parent(parent) } - - /** Alias for calling [parent] with `Parent.ofSpanParentStruct(spanParentStruct)`. */ - fun parent(spanParentStruct: Parent.SpanParentStruct) = apply { - body.parent(spanParentStruct) - } - - /** Alias for calling [parent] with `Parent.ofString(string)`. */ - fun parent(string: String) = apply { body.parent(string) } - - /** - * Whether to stream the response. If true, results will be returned in the Braintrust SSE - * format. - */ - fun stream(stream: Boolean?) = apply { body.stream(stream) } - - /** - * Alias for [Builder.stream]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun stream(stream: Boolean) = stream(stream as Boolean?) - - /** Alias for calling [Builder.stream] with `stream.orElse(null)`. */ - fun stream(stream: Optional) = stream(stream.getOrNull()) - - /** - * Sets [Builder.stream] to an arbitrary JSON value. - * - * You should usually call [Builder.stream] with a well-typed [Boolean] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun stream(stream: JsonField) = apply { body.stream(stream) } - - /** The version of the function */ - fun version(version: String) = apply { body.version(version) } - - /** - * Sets [Builder.version] to an arbitrary JSON value. - * - * You should usually call [Builder.version] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun version(version: JsonField) = apply { body.version(version) } - - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) - } - - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } - - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) - } - - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } - - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } - - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } - - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(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 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) - } + putAllAdditionalProperties(additionalProperties) + } - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Body = + Body( + expected, + input, + (messages ?: JsonMissing.of()).map { it.toImmutable() }, + metadata, + mode, + parent, + stream, + version, + additionalProperties.toMutableMap(), + ) } - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } + private var validated: Boolean = false - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + fun validate(): Body = apply { + if (validated) { + return@apply + } + + messages().ifPresent { it.forEach { it.validate() } } + metadata().ifPresent { it.validate() } + mode() + parent().ifPresent { it.validate() } + stream() + version() + validated = true } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) + return /* spotless:off */ other is Body && expected == other.expected && input == other.input && messages == other.messages && metadata == other.metadata && mode == other.mode && parent == other.parent && stream == other.stream && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ } - /** - * Returns an immutable instance of [FunctionInvokeParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .functionId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): FunctionInvokeParams = - FunctionInvokeParams( - checkRequired("functionId", functionId), - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(expected, input, messages, metadata, mode, parent, stream, version, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{expected=$expected, input=$input, messages=$messages, metadata=$metadata, mode=$mode, parent=$parent, stream=$stream, version=$version, additionalProperties=$additionalProperties}" } @JsonDeserialize(using = Message.Deserializer::class) @@ -1059,23 +1064,23 @@ private constructor( } } - @NoAutoDetect class System - @JsonCreator private constructor( - @JsonProperty("role") - @ExcludeMissing - private val role: JsonField = JsonMissing.of(), - @JsonProperty("content") - @ExcludeMissing - private val content: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val role: JsonField, + private val content: JsonField, + private val name: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("role") @ExcludeMissing role: JsonField = JsonMissing.of(), + @JsonProperty("content") + @ExcludeMissing + content: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + ) : this(role, content, name, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -1116,22 +1121,15 @@ private constructor( */ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): System = apply { - if (validated) { - return@apply - } - - role() - content() - name() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1236,10 +1234,23 @@ private constructor( checkRequired("role", role), content, name, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): System = apply { + if (validated) { + return@apply + } + + role() + content() + name() + validated = true + } + class Role @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -1355,23 +1366,23 @@ private constructor( "System{role=$role, content=$content, name=$name, additionalProperties=$additionalProperties}" } - @NoAutoDetect class User - @JsonCreator private constructor( - @JsonProperty("role") - @ExcludeMissing - private val role: JsonField = JsonMissing.of(), - @JsonProperty("content") - @ExcludeMissing - private val content: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val role: JsonField, + private val content: JsonField, + private val name: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("role") @ExcludeMissing role: JsonField = JsonMissing.of(), + @JsonProperty("content") + @ExcludeMissing + content: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + ) : this(role, content, name, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -1412,22 +1423,15 @@ private constructor( */ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): User = apply { - if (validated) { - return@apply - } - - role() - content().ifPresent { it.validate() } - name() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1539,10 +1543,23 @@ private constructor( checkRequired("role", role), content, name, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): User = apply { + if (validated) { + return@apply + } + + role() + content().ifPresent { it.validate() } + name() + validated = true + } + class Role @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -1953,30 +1970,31 @@ private constructor( "User{role=$role, content=$content, name=$name, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Assistant - @JsonCreator private constructor( - @JsonProperty("role") - @ExcludeMissing - private val role: JsonField = JsonMissing.of(), - @JsonProperty("content") - @ExcludeMissing - private val content: JsonField = JsonMissing.of(), - @JsonProperty("function_call") - @ExcludeMissing - private val functionCall: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("tool_calls") - @ExcludeMissing - private val toolCalls: JsonField> = - JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val role: JsonField, + private val content: JsonField, + private val functionCall: JsonField, + private val name: JsonField, + private val toolCalls: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("role") @ExcludeMissing role: JsonField = JsonMissing.of(), + @JsonProperty("content") + @ExcludeMissing + content: JsonField = JsonMissing.of(), + @JsonProperty("function_call") + @ExcludeMissing + functionCall: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("tool_calls") + @ExcludeMissing + toolCalls: JsonField> = JsonMissing.of(), + ) : this(role, content, functionCall, name, toolCalls, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -2051,24 +2069,15 @@ private constructor( @ExcludeMissing fun _toolCalls(): JsonField> = toolCalls + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Assistant = apply { - if (validated) { - return@apply - } - - role() - content() - functionCall().ifPresent { it.validate() } - name() - toolCalls().ifPresent { it.forEach { it.validate() } } - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -2233,10 +2242,25 @@ private constructor( functionCall, name, (toolCalls ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Assistant = apply { + if (validated) { + return@apply + } + + role() + content() + functionCall().ifPresent { it.validate() } + name() + toolCalls().ifPresent { it.forEach { it.validate() } } + validated = true + } + class Role @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2334,20 +2358,21 @@ private constructor( override fun toString() = value.toString() } - @NoAutoDetect class FunctionCall - @JsonCreator private constructor( - @JsonProperty("arguments") - @ExcludeMissing - private val arguments: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val arguments: JsonField, + private val name: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("arguments") + @ExcludeMissing + arguments: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + ) : this(arguments, name, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type * or is unexpectedly missing or null (e.g. if the server responded with an @@ -2380,21 +2405,15 @@ private constructor( */ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): FunctionCall = apply { - if (validated) { - return@apply - } - - arguments() - name() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -2489,10 +2508,22 @@ private constructor( FunctionCall( checkRequired("arguments", arguments), checkRequired("name", name), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): FunctionCall = apply { + if (validated) { + return@apply + } + + arguments() + name() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2529,23 +2560,25 @@ private constructor( "Assistant{role=$role, content=$content, functionCall=$functionCall, name=$name, toolCalls=$toolCalls, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Tool - @JsonCreator private constructor( - @JsonProperty("role") - @ExcludeMissing - private val role: JsonField = JsonMissing.of(), - @JsonProperty("content") - @ExcludeMissing - private val content: JsonField = JsonMissing.of(), - @JsonProperty("tool_call_id") - @ExcludeMissing - private val toolCallId: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val role: JsonField, + private val content: JsonField, + private val toolCallId: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("role") @ExcludeMissing role: JsonField = JsonMissing.of(), + @JsonProperty("content") + @ExcludeMissing + content: JsonField = JsonMissing.of(), + @JsonProperty("tool_call_id") + @ExcludeMissing + toolCallId: JsonField = JsonMissing.of(), + ) : this(role, content, toolCallId, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -2590,22 +2623,15 @@ private constructor( @ExcludeMissing fun _toolCallId(): JsonField = toolCallId + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Tool = apply { - if (validated) { - return@apply - } - - role() - content() - toolCallId() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -2712,10 +2738,23 @@ private constructor( checkRequired("role", role), content, toolCallId, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Tool = apply { + if (validated) { + return@apply + } + + role() + content() + toolCallId() + validated = true + } + class Role @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2831,23 +2870,23 @@ private constructor( "Tool{role=$role, content=$content, toolCallId=$toolCallId, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Function - @JsonCreator private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("role") - @ExcludeMissing - private val role: JsonField = JsonMissing.of(), - @JsonProperty("content") - @ExcludeMissing - private val content: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val name: JsonField, + private val role: JsonField, + private val content: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("role") @ExcludeMissing role: JsonField = JsonMissing.of(), + @JsonProperty("content") + @ExcludeMissing + content: JsonField = JsonMissing.of(), + ) : this(name, role, content, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -2889,22 +2928,15 @@ private constructor( */ @JsonProperty("content") @ExcludeMissing fun _content(): JsonField = content + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Function = apply { - if (validated) { - return@apply - } - - name() - role() - content() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -3011,10 +3043,23 @@ private constructor( checkRequired("name", name), checkRequired("role", role), content, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Function = apply { + if (validated) { + return@apply + } + + name() + role() + content() + validated = true + } + class Role @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -3130,20 +3175,21 @@ private constructor( "Function{name=$name, role=$role, content=$content, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Fallback - @JsonCreator private constructor( - @JsonProperty("role") - @ExcludeMissing - private val role: JsonField = JsonMissing.of(), - @JsonProperty("content") - @ExcludeMissing - private val content: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val role: JsonField, + private val content: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("role") @ExcludeMissing role: JsonField = JsonMissing.of(), + @JsonProperty("content") + @ExcludeMissing + content: JsonField = JsonMissing.of(), + ) : this(role, content, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -3171,21 +3217,15 @@ private constructor( */ @JsonProperty("content") @ExcludeMissing fun _content(): JsonField = content + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Fallback = apply { - if (validated) { - return@apply - } - - role() - content() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -3279,10 +3319,22 @@ private constructor( Fallback( checkRequired("role", role), content, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Fallback = apply { + if (validated) { + return@apply + } + + role() + content() + validated = true + } + class Role @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -3400,27 +3452,20 @@ private constructor( } /** Any relevant metadata */ - @NoAutoDetect class Metadata - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -3464,7 +3509,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { @@ -3727,26 +3782,31 @@ private constructor( } /** Span parent properties */ - @NoAutoDetect class SpanParentStruct - @JsonCreator private constructor( - @JsonProperty("object_id") - @ExcludeMissing - private val objectId: JsonField = JsonMissing.of(), - @JsonProperty("object_type") - @ExcludeMissing - private val objectType: JsonField = JsonMissing.of(), - @JsonProperty("propagated_event") - @ExcludeMissing - private val propagatedEvent: JsonField = JsonMissing.of(), - @JsonProperty("row_ids") - @ExcludeMissing - private val rowIds: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val objectId: JsonField, + private val objectType: JsonField, + private val propagatedEvent: JsonField, + private val rowIds: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("object_id") + @ExcludeMissing + objectId: JsonField = JsonMissing.of(), + @JsonProperty("object_type") + @ExcludeMissing + objectType: JsonField = JsonMissing.of(), + @JsonProperty("propagated_event") + @ExcludeMissing + propagatedEvent: JsonField = JsonMissing.of(), + @JsonProperty("row_ids") + @ExcludeMissing + rowIds: JsonField = JsonMissing.of(), + ) : this(objectId, objectType, propagatedEvent, rowIds, mutableMapOf()) + /** * The id of the container object you are logging to * @@ -3815,23 +3875,15 @@ private constructor( */ @JsonProperty("row_ids") @ExcludeMissing fun _rowIds(): JsonField = rowIds + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): SpanParentStruct = apply { - if (validated) { - return@apply - } - - objectId() - objectType() - propagatedEvent().ifPresent { it.validate() } - rowIds().ifPresent { it.validate() } - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -3969,10 +4021,24 @@ private constructor( checkRequired("objectType", objectType), propagatedEvent, rowIds, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): SpanParentStruct = apply { + if (validated) { + return@apply + } + + objectId() + objectType() + propagatedEvent().ifPresent { it.validate() } + rowIds().ifPresent { it.validate() } + validated = true + } + class ObjectType @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -4085,27 +4151,20 @@ private constructor( } /** Include these properties in every span created under this parent */ - @NoAutoDetect class PropagatedEvent - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): PropagatedEvent = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -4155,7 +4214,17 @@ private constructor( * Further updates to this [Builder] will not mutate the returned instance. */ fun build(): PropagatedEvent = - PropagatedEvent(additionalProperties.toImmutable()) + PropagatedEvent(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): PropagatedEvent = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { @@ -4177,23 +4246,25 @@ private constructor( } /** Identifiers for the row to to log a subspan under */ - @NoAutoDetect class RowIds - @JsonCreator private constructor( - @JsonProperty("id") - @ExcludeMissing - private val id: JsonField = JsonMissing.of(), - @JsonProperty("root_span_id") - @ExcludeMissing - private val rootSpanId: JsonField = JsonMissing.of(), - @JsonProperty("span_id") - @ExcludeMissing - private val spanId: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val rootSpanId: JsonField, + private val spanId: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("root_span_id") + @ExcludeMissing + rootSpanId: JsonField = JsonMissing.of(), + @JsonProperty("span_id") + @ExcludeMissing + spanId: JsonField = JsonMissing.of(), + ) : this(id, rootSpanId, spanId, mutableMapOf()) + /** * The id of the row * @@ -4246,22 +4317,15 @@ private constructor( */ @JsonProperty("span_id") @ExcludeMissing fun _spanId(): JsonField = spanId + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): RowIds = apply { - if (validated) { - return@apply - } - - id() - rootSpanId() - spanId() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -4375,10 +4439,23 @@ private constructor( checkRequired("id", id), checkRequired("rootSpanId", rootSpanId), checkRequired("spanId", spanId), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): RowIds = apply { + if (validated) { + return@apply + } + + id() + rootSpanId() + spanId() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeResponse.kt index d7035b68..b590d1f5 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeResponse.kt @@ -4,35 +4,27 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator +import java.util.Collections import java.util.Objects -@NoAutoDetect class FunctionInvokeResponse -@JsonCreator -private constructor( - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap() -) { +private constructor(private val additionalProperties: MutableMap) { - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): FunctionInvokeResponse = apply { - if (validated) { - return@apply - } + @JsonCreator private constructor() : this(mutableMapOf()) - validated = true + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + fun toBuilder() = Builder().from(this) companion object { @@ -76,7 +68,17 @@ private constructor( * Further updates to this [Builder] will not mutate the returned instance. */ fun build(): FunctionInvokeResponse = - FunctionInvokeResponse(additionalProperties.toImmutable()) + FunctionInvokeResponse(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): FunctionInvokeResponse = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPage.kt index 4f51a5ad..98c86b49 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPage.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.blocking.FunctionService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -87,23 +85,30 @@ private constructor( FunctionListPage(functionsService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -161,7 +166,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageAsync.kt index 5979e5bf..46945c42 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageAsync.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.async.FunctionServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -92,23 +90,30 @@ private constructor( ) = FunctionListPageAsync(functionsService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -168,7 +173,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListParams.kt index 534f5284..462ff0c3 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListParams.kt @@ -5,7 +5,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.BaseDeserializer import com.braintrustdata.api.core.BaseSerializer import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers @@ -96,35 +95,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = - QueryParams.builder() - .apply { - endingBefore?.let { put("ending_before", it) } - functionName?.let { put("function_name", it) } - ids?.accept( - object : Ids.Visitor { - override fun visitString(string: String) { - put("ids", string) - } - - override fun visitStrings(strings: List) { - put("ids", strings.joinToString(",")) - } - } - ) - limit?.let { put("limit", it.toString()) } - orgName?.let { put("org_name", it) } - projectId?.let { put("project_id", it) } - projectName?.let { put("project_name", it) } - slug?.let { put("slug", it) } - startingAfter?.let { put("starting_after", it) } - version?.let { put("version", it) } - putAll(additionalQueryParams) - } - .build() - fun toBuilder() = Builder().from(this) companion object { @@ -136,7 +106,6 @@ private constructor( } /** A builder for [FunctionListParams]. */ - @NoAutoDetect class Builder internal constructor() { private var endingBefore: String? = null @@ -382,6 +351,35 @@ private constructor( ) } + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + endingBefore?.let { put("ending_before", it) } + functionName?.let { put("function_name", it) } + ids?.accept( + object : Ids.Visitor { + override fun visitString(string: String) { + put("ids", string) + } + + override fun visitStrings(strings: List) { + put("ids", strings.joinToString(",")) + } + } + ) + limit?.let { put("limit", it.toString()) } + orgName?.let { put("org_name", it) } + projectId?.let { put("project_id", it) } + projectName?.let { put("project_name", it) } + slug?.let { put("slug", it) } + startingAfter?.let { put("starting_after", it) } + version?.let { put("version", it) } + putAll(additionalQueryParams) + } + .build() + /** * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionReplaceParams.kt index 78279e3e..f09edae4 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionReplaceParams.kt @@ -9,14 +9,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.models.CodeBundle.* @@ -31,6 +29,7 @@ import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -196,529 +195,317 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("function_data") - @ExcludeMissing - private val functionData: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("project_id") - @ExcludeMissing - private val projectId: JsonField = JsonMissing.of(), - @JsonProperty("slug") - @ExcludeMissing - private val slug: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("function_schema") - @ExcludeMissing - private val functionSchema: JsonField = JsonMissing.of(), - @JsonProperty("function_type") - @ExcludeMissing - private val functionType: JsonField = JsonMissing.of(), - @JsonProperty("origin") - @ExcludeMissing - private val origin: JsonField = JsonMissing.of(), - @JsonProperty("prompt_data") - @ExcludeMissing - private val promptData: JsonField = JsonMissing.of(), - @JsonProperty("tags") - @ExcludeMissing - private val tags: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + fun toBuilder() = Builder().from(this) - /** - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun functionData(): FunctionData = functionData.getRequired("function_data") + companion object { /** - * Name of the prompt + * Returns a mutable builder for constructing an instance of [FunctionReplaceParams]. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + * The following fields are required: + * ```java + * .functionData() + * .name() + * .projectId() + * .slug() + * ``` */ - fun name(): String = name.getRequired("name") + @JvmStatic fun builder() = Builder() + } - /** - * Unique identifier for the project that the prompt belongs under - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun projectId(): String = projectId.getRequired("project_id") + /** A builder for [FunctionReplaceParams]. */ + class Builder internal constructor() { - /** - * Unique identifier for the prompt - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun slug(): String = slug.getRequired("slug") + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - /** - * Textual description of the prompt - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + @JvmSynthetic + internal fun from(functionReplaceParams: FunctionReplaceParams) = apply { + body = functionReplaceParams.body.toBuilder() + additionalHeaders = functionReplaceParams.additionalHeaders.toBuilder() + additionalQueryParams = functionReplaceParams.additionalQueryParams.toBuilder() + } + + fun functionData(functionData: FunctionData) = apply { body.functionData(functionData) } /** - * JSON schema for the function's parameters and return type + * Sets [Builder.functionData] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.functionData] with a well-typed [FunctionData] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun functionSchema(): Optional = - Optional.ofNullable(functionSchema.getNullable("function_schema")) + fun functionData(functionData: JsonField) = apply { + body.functionData(functionData) + } - /** - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun functionType(): Optional = - Optional.ofNullable(functionType.getNullable("function_type")) + /** Alias for calling [functionData] with `FunctionData.ofPrompt(prompt)`. */ + fun functionData(prompt: FunctionData.Prompt) = apply { body.functionData(prompt) } - /** - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun origin(): Optional = Optional.ofNullable(origin.getNullable("origin")) + /** Alias for calling [functionData] with `FunctionData.ofCode(code)`. */ + fun functionData(code: FunctionData.Code) = apply { body.functionData(code) } - /** - * The prompt, model, and its parameters - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun promptData(): Optional = - Optional.ofNullable(promptData.getNullable("prompt_data")) + /** Alias for calling [functionData] with `FunctionData.ofGlobal(global)`. */ + fun functionData(global: FunctionData.Global) = apply { body.functionData(global) } + + /** Name of the prompt */ + fun name(name: String) = apply { body.name(name) } /** - * A list of tags for the prompt + * Sets [Builder.name] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) + fun name(name: JsonField) = apply { body.name(name) } + + /** Unique identifier for the project that the prompt belongs under */ + fun projectId(projectId: String) = apply { body.projectId(projectId) } /** - * Returns the raw JSON value of [functionData]. + * Sets [Builder.projectId] to an arbitrary JSON value. * - * Unlike [functionData], this method doesn't throw if the JSON field has an unexpected - * type. + * You should usually call [Builder.projectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("function_data") - @ExcludeMissing - fun _functionData(): JsonField = functionData + fun projectId(projectId: JsonField) = apply { body.projectId(projectId) } + + /** Unique identifier for the prompt */ + fun slug(slug: String) = apply { body.slug(slug) } /** - * Returns the raw JSON value of [name]. + * Sets [Builder.slug] to an arbitrary JSON value. * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.slug] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + fun slug(slug: JsonField) = apply { body.slug(slug) } + + /** Textual description of the prompt */ + fun description(description: String?) = apply { body.description(description) } + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) /** - * Returns the raw JSON value of [projectId]. + * Sets [Builder.description] to an arbitrary JSON value. * - * Unlike [projectId], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("project_id") @ExcludeMissing fun _projectId(): JsonField = projectId + fun description(description: JsonField) = apply { body.description(description) } + + /** JSON schema for the function's parameters and return type */ + fun functionSchema(functionSchema: FunctionSchema?) = apply { + body.functionSchema(functionSchema) + } + + /** Alias for calling [Builder.functionSchema] with `functionSchema.orElse(null)`. */ + fun functionSchema(functionSchema: Optional) = + functionSchema(functionSchema.getOrNull()) /** - * Returns the raw JSON value of [slug]. + * Sets [Builder.functionSchema] to an arbitrary JSON value. * - * Unlike [slug], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.functionSchema] with a well-typed [FunctionSchema] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("slug") @ExcludeMissing fun _slug(): JsonField = slug + fun functionSchema(functionSchema: JsonField) = apply { + body.functionSchema(functionSchema) + } + + fun functionType(functionType: FunctionType?) = apply { body.functionType(functionType) } + + /** Alias for calling [Builder.functionType] with `functionType.orElse(null)`. */ + fun functionType(functionType: Optional) = + functionType(functionType.getOrNull()) /** - * Returns the raw JSON value of [description]. + * Sets [Builder.functionType] to an arbitrary JSON value. * - * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.functionType] with a well-typed [FunctionType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("description") - @ExcludeMissing - fun _description(): JsonField = description + fun functionType(functionType: JsonField) = apply { + body.functionType(functionType) + } + + fun origin(origin: Origin?) = apply { body.origin(origin) } + + /** Alias for calling [Builder.origin] with `origin.orElse(null)`. */ + fun origin(origin: Optional) = origin(origin.getOrNull()) /** - * Returns the raw JSON value of [functionSchema]. + * Sets [Builder.origin] to an arbitrary JSON value. * - * Unlike [functionSchema], this method doesn't throw if the JSON field has an unexpected - * type. + * You should usually call [Builder.origin] with a well-typed [Origin] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("function_schema") - @ExcludeMissing - fun _functionSchema(): JsonField = functionSchema + fun origin(origin: JsonField) = apply { body.origin(origin) } + + /** The prompt, model, and its parameters */ + fun promptData(promptData: PromptData?) = apply { body.promptData(promptData) } + + /** Alias for calling [Builder.promptData] with `promptData.orElse(null)`. */ + fun promptData(promptData: Optional) = promptData(promptData.getOrNull()) /** - * Returns the raw JSON value of [functionType]. + * Sets [Builder.promptData] to an arbitrary JSON value. * - * Unlike [functionType], this method doesn't throw if the JSON field has an unexpected - * type. + * You should usually call [Builder.promptData] with a well-typed [PromptData] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("function_type") - @ExcludeMissing - fun _functionType(): JsonField = functionType + fun promptData(promptData: JsonField) = apply { body.promptData(promptData) } + + /** A list of tags for the prompt */ + fun tags(tags: List?) = apply { body.tags(tags) } + + /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ + fun tags(tags: Optional>) = tags(tags.getOrNull()) /** - * Returns the raw JSON value of [origin]. + * Sets [Builder.tags] to an arbitrary JSON value. * - * Unlike [origin], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.tags] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("origin") @ExcludeMissing fun _origin(): JsonField = origin + fun tags(tags: JsonField>) = apply { body.tags(tags) } /** - * Returns the raw JSON value of [promptData]. + * Adds a single [String] to [tags]. * - * Unlike [promptData], this method doesn't throw if the JSON field has an unexpected type. + * @throws IllegalStateException if the field was previously set to a non-list. */ - @JsonProperty("prompt_data") - @ExcludeMissing - fun _promptData(): JsonField = promptData - - /** - * Returns the raw JSON value of [tags]. - * - * Unlike [tags], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } + fun addTag(tag: String) = apply { body.addTag(tag) } - functionData().validate() - name() - projectId() - slug() - description() - functionSchema().ifPresent { it.validate() } - functionType() - origin().ifPresent { it.validate() } - promptData().ifPresent { it.validate() } - tags() - validated = true + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) } - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .functionData() - * .name() - * .projectId() - * .slug() - * ``` - */ - @JvmStatic fun builder() = Builder() + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) } - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var functionData: JsonField? = null - private var name: JsonField? = null - private var projectId: JsonField? = null - private var slug: JsonField? = null - private var description: JsonField = JsonMissing.of() - private var functionSchema: JsonField = JsonMissing.of() - private var functionType: JsonField = JsonMissing.of() - private var origin: JsonField = JsonMissing.of() - private var promptData: JsonField = JsonMissing.of() - private var tags: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - functionData = body.functionData - name = body.name - projectId = body.projectId - slug = body.slug - description = body.description - functionSchema = body.functionSchema - functionType = body.functionType - origin = body.origin - promptData = body.promptData - tags = body.tags.map { it.toMutableList() } - additionalProperties = body.additionalProperties.toMutableMap() - } - - fun functionData(functionData: FunctionData) = functionData(JsonField.of(functionData)) - - /** - * Sets [Builder.functionData] to an arbitrary JSON value. - * - * You should usually call [Builder.functionData] with a well-typed [FunctionData] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun functionData(functionData: JsonField) = apply { - this.functionData = functionData - } - - /** Alias for calling [functionData] with `FunctionData.ofPrompt(prompt)`. */ - fun functionData(prompt: FunctionData.Prompt) = - functionData(FunctionData.ofPrompt(prompt)) - - /** Alias for calling [functionData] with `FunctionData.ofCode(code)`. */ - fun functionData(code: FunctionData.Code) = functionData(FunctionData.ofCode(code)) - - /** Alias for calling [functionData] with `FunctionData.ofGlobal(global)`. */ - fun functionData(global: FunctionData.Global) = - functionData(FunctionData.ofGlobal(global)) - - /** Name of the prompt */ - fun name(name: String) = name(JsonField.of(name)) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } - - /** Unique identifier for the project that the prompt belongs under */ - fun projectId(projectId: String) = projectId(JsonField.of(projectId)) - - /** - * Sets [Builder.projectId] to an arbitrary JSON value. - * - * You should usually call [Builder.projectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun projectId(projectId: JsonField) = apply { this.projectId = projectId } - - /** Unique identifier for the prompt */ - fun slug(slug: String) = slug(JsonField.of(slug)) - - /** - * Sets [Builder.slug] to an arbitrary JSON value. - * - * You should usually call [Builder.slug] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun slug(slug: JsonField) = apply { this.slug = slug } - - /** Textual description of the prompt */ - fun description(description: String?) = description(JsonField.ofNullable(description)) - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) - - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun description(description: JsonField) = apply { - this.description = description - } - - /** JSON schema for the function's parameters and return type */ - fun functionSchema(functionSchema: FunctionSchema?) = - functionSchema(JsonField.ofNullable(functionSchema)) - - /** Alias for calling [Builder.functionSchema] with `functionSchema.orElse(null)`. */ - fun functionSchema(functionSchema: Optional) = - functionSchema(functionSchema.getOrNull()) - - /** - * Sets [Builder.functionSchema] to an arbitrary JSON value. - * - * You should usually call [Builder.functionSchema] with a well-typed [FunctionSchema] - * value instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun functionSchema(functionSchema: JsonField) = apply { - this.functionSchema = functionSchema + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) } - fun functionType(functionType: FunctionType?) = - functionType(JsonField.ofNullable(functionType)) + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - /** Alias for calling [Builder.functionType] with `functionType.orElse(null)`. */ - fun functionType(functionType: Optional) = - functionType(functionType.getOrNull()) + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } - /** - * Sets [Builder.functionType] to an arbitrary JSON value. - * - * You should usually call [Builder.functionType] with a well-typed [FunctionType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun functionType(functionType: JsonField) = apply { - this.functionType = functionType - } + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - fun origin(origin: Origin?) = origin(JsonField.ofNullable(origin)) + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** Alias for calling [Builder.origin] with `origin.orElse(null)`. */ - fun origin(origin: Optional) = origin(origin.getOrNull()) + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } - /** - * Sets [Builder.origin] to an arbitrary JSON value. - * - * You should usually call [Builder.origin] with a well-typed [Origin] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun origin(origin: JsonField) = apply { this.origin = origin } + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - /** The prompt, model, and its parameters */ - fun promptData(promptData: PromptData?) = promptData(JsonField.ofNullable(promptData)) + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** Alias for calling [Builder.promptData] with `promptData.orElse(null)`. */ - fun promptData(promptData: Optional) = promptData(promptData.getOrNull()) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** - * Sets [Builder.promptData] to an arbitrary JSON value. - * - * You should usually call [Builder.promptData] with a well-typed [PromptData] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun promptData(promptData: JsonField) = apply { - this.promptData = promptData - } + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - /** A list of tags for the prompt */ - fun tags(tags: List?) = tags(JsonField.ofNullable(tags)) + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ - fun tags(tags: Optional>) = tags(tags.getOrNull()) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Sets [Builder.tags] to an arbitrary JSON value. - * - * You should usually call [Builder.tags] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun tags(tags: JsonField>) = apply { - this.tags = tags.map { it.toMutableList() } - } + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Adds a single [String] to [tags]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addTag(tag: String) = apply { - tags = - (tags ?: JsonField.of(mutableListOf())).also { checkKnown("tags", it).add(tag) } - } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .functionData() - * .name() - * .projectId() - * .slug() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("functionData", functionData), - checkRequired("name", name), - checkRequired("projectId", projectId), - checkRequired("slug", slug), - description, - functionSchema, - functionType, - origin, - promptData, - (tags ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), - ) + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - return /* spotless:off */ other is Body && functionData == other.functionData && name == other.name && projectId == other.projectId && slug == other.slug && description == other.description && functionSchema == other.functionSchema && functionType == other.functionType && origin == other.origin && promptData == other.promptData && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(functionData, name, projectId, slug, description, functionSchema, functionType, origin, promptData, tags, additionalProperties) } - /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } - override fun hashCode(): Int = hashCode + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - override fun toString() = - "Body{functionData=$functionData, name=$name, projectId=$projectId, slug=$slug, description=$description, functionSchema=$functionSchema, functionType=$functionType, origin=$origin, promptData=$promptData, tags=$tags, additionalProperties=$additionalProperties}" - } + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - fun toBuilder() = Builder().from(this) + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - companion object { + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } /** - * Returns a mutable builder for constructing an instance of [FunctionReplaceParams]. + * Returns an immutable instance of [FunctionReplaceParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java @@ -727,321 +514,553 @@ private constructor( * .projectId() * .slug() * ``` + * + * @throws IllegalStateException if any required field is unset. */ - @JvmStatic fun builder() = Builder() + fun build(): FunctionReplaceParams = + FunctionReplaceParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) } - /** A builder for [FunctionReplaceParams]. */ - @NoAutoDetect - class Builder internal constructor() { + @JvmSynthetic internal fun _body(): Body = body - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun from(functionReplaceParams: FunctionReplaceParams) = apply { - body = functionReplaceParams.body.toBuilder() - additionalHeaders = functionReplaceParams.additionalHeaders.toBuilder() - additionalQueryParams = functionReplaceParams.additionalQueryParams.toBuilder() - } + override fun _queryParams(): QueryParams = additionalQueryParams - fun functionData(functionData: FunctionData) = apply { body.functionData(functionData) } + class Body + private constructor( + private val functionData: JsonField, + private val name: JsonField, + private val projectId: JsonField, + private val slug: JsonField, + private val description: JsonField, + private val functionSchema: JsonField, + private val functionType: JsonField, + private val origin: JsonField, + private val promptData: JsonField, + private val tags: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("function_data") + @ExcludeMissing + functionData: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("slug") @ExcludeMissing slug: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("function_schema") + @ExcludeMissing + functionSchema: JsonField = JsonMissing.of(), + @JsonProperty("function_type") + @ExcludeMissing + functionType: JsonField = JsonMissing.of(), + @JsonProperty("origin") @ExcludeMissing origin: JsonField = JsonMissing.of(), + @JsonProperty("prompt_data") + @ExcludeMissing + promptData: JsonField = JsonMissing.of(), + @JsonProperty("tags") @ExcludeMissing tags: JsonField> = JsonMissing.of(), + ) : this( + functionData, + name, + projectId, + slug, + description, + functionSchema, + functionType, + origin, + promptData, + tags, + mutableMapOf(), + ) /** - * Sets [Builder.functionData] to an arbitrary JSON value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun functionData(): FunctionData = functionData.getRequired("function_data") + + /** + * Name of the prompt * - * You should usually call [Builder.functionData] with a well-typed [FunctionData] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun functionData(functionData: JsonField) = apply { - body.functionData(functionData) - } + fun name(): String = name.getRequired("name") - /** Alias for calling [functionData] with `FunctionData.ofPrompt(prompt)`. */ - fun functionData(prompt: FunctionData.Prompt) = apply { body.functionData(prompt) } + /** + * Unique identifier for the project that the prompt belongs under + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun projectId(): String = projectId.getRequired("project_id") - /** Alias for calling [functionData] with `FunctionData.ofCode(code)`. */ - fun functionData(code: FunctionData.Code) = apply { body.functionData(code) } + /** + * Unique identifier for the prompt + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun slug(): String = slug.getRequired("slug") - /** Alias for calling [functionData] with `FunctionData.ofGlobal(global)`. */ - fun functionData(global: FunctionData.Global) = apply { body.functionData(global) } + /** + * Textual description of the prompt + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun description(): Optional = + Optional.ofNullable(description.getNullable("description")) - /** Name of the prompt */ - fun name(name: String) = apply { body.name(name) } + /** + * JSON schema for the function's parameters and return type + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun functionSchema(): Optional = + Optional.ofNullable(functionSchema.getNullable("function_schema")) /** - * Sets [Builder.name] to an arbitrary JSON value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun functionType(): Optional = + Optional.ofNullable(functionType.getNullable("function_type")) + + /** + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun origin(): Optional = Optional.ofNullable(origin.getNullable("origin")) + + /** + * The prompt, model, and its parameters * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun name(name: JsonField) = apply { body.name(name) } + fun promptData(): Optional = + Optional.ofNullable(promptData.getNullable("prompt_data")) - /** Unique identifier for the project that the prompt belongs under */ - fun projectId(projectId: String) = apply { body.projectId(projectId) } + /** + * A list of tags for the prompt + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) /** - * Sets [Builder.projectId] to an arbitrary JSON value. + * Returns the raw JSON value of [functionData]. * - * You should usually call [Builder.projectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [functionData], this method doesn't throw if the JSON field has an unexpected + * type. */ - fun projectId(projectId: JsonField) = apply { body.projectId(projectId) } + @JsonProperty("function_data") + @ExcludeMissing + fun _functionData(): JsonField = functionData - /** Unique identifier for the prompt */ - fun slug(slug: String) = apply { body.slug(slug) } + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [projectId]. + * + * Unlike [projectId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("project_id") @ExcludeMissing fun _projectId(): JsonField = projectId + + /** + * Returns the raw JSON value of [slug]. + * + * Unlike [slug], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("slug") @ExcludeMissing fun _slug(): JsonField = slug + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [functionSchema]. + * + * Unlike [functionSchema], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("function_schema") + @ExcludeMissing + fun _functionSchema(): JsonField = functionSchema + + /** + * Returns the raw JSON value of [functionType]. + * + * Unlike [functionType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("function_type") + @ExcludeMissing + fun _functionType(): JsonField = functionType + + /** + * Returns the raw JSON value of [origin]. + * + * Unlike [origin], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("origin") @ExcludeMissing fun _origin(): JsonField = origin /** - * Sets [Builder.slug] to an arbitrary JSON value. + * Returns the raw JSON value of [promptData]. * - * You should usually call [Builder.slug] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [promptData], this method doesn't throw if the JSON field has an unexpected type. */ - fun slug(slug: JsonField) = apply { body.slug(slug) } - - /** Textual description of the prompt */ - fun description(description: String?) = apply { body.description(description) } - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) + @JsonProperty("prompt_data") + @ExcludeMissing + fun _promptData(): JsonField = promptData /** - * Sets [Builder.description] to an arbitrary JSON value. + * Returns the raw JSON value of [tags]. * - * You should usually call [Builder.description] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [tags], this method doesn't throw if the JSON field has an unexpected type. */ - fun description(description: JsonField) = apply { body.description(description) } + @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags - /** JSON schema for the function's parameters and return type */ - fun functionSchema(functionSchema: FunctionSchema?) = apply { - body.functionSchema(functionSchema) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - /** Alias for calling [Builder.functionSchema] with `functionSchema.orElse(null)`. */ - fun functionSchema(functionSchema: Optional) = - functionSchema(functionSchema.getOrNull()) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - /** - * Sets [Builder.functionSchema] to an arbitrary JSON value. - * - * You should usually call [Builder.functionSchema] with a well-typed [FunctionSchema] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun functionSchema(functionSchema: JsonField) = apply { - body.functionSchema(functionSchema) + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .functionData() + * .name() + * .projectId() + * .slug() + * ``` + */ + @JvmStatic fun builder() = Builder() } - fun functionType(functionType: FunctionType?) = apply { body.functionType(functionType) } + /** A builder for [Body]. */ + class Builder internal constructor() { - /** Alias for calling [Builder.functionType] with `functionType.orElse(null)`. */ - fun functionType(functionType: Optional) = - functionType(functionType.getOrNull()) + private var functionData: JsonField? = null + private var name: JsonField? = null + private var projectId: JsonField? = null + private var slug: JsonField? = null + private var description: JsonField = JsonMissing.of() + private var functionSchema: JsonField = JsonMissing.of() + private var functionType: JsonField = JsonMissing.of() + private var origin: JsonField = JsonMissing.of() + private var promptData: JsonField = JsonMissing.of() + private var tags: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() - /** - * Sets [Builder.functionType] to an arbitrary JSON value. - * - * You should usually call [Builder.functionType] with a well-typed [FunctionType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun functionType(functionType: JsonField) = apply { - body.functionType(functionType) - } + @JvmSynthetic + internal fun from(body: Body) = apply { + functionData = body.functionData + name = body.name + projectId = body.projectId + slug = body.slug + description = body.description + functionSchema = body.functionSchema + functionType = body.functionType + origin = body.origin + promptData = body.promptData + tags = body.tags.map { it.toMutableList() } + additionalProperties = body.additionalProperties.toMutableMap() + } - fun origin(origin: Origin?) = apply { body.origin(origin) } + fun functionData(functionData: FunctionData) = functionData(JsonField.of(functionData)) - /** Alias for calling [Builder.origin] with `origin.orElse(null)`. */ - fun origin(origin: Optional) = origin(origin.getOrNull()) + /** + * Sets [Builder.functionData] to an arbitrary JSON value. + * + * You should usually call [Builder.functionData] with a well-typed [FunctionData] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun functionData(functionData: JsonField) = apply { + this.functionData = functionData + } - /** - * Sets [Builder.origin] to an arbitrary JSON value. - * - * You should usually call [Builder.origin] with a well-typed [Origin] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun origin(origin: JsonField) = apply { body.origin(origin) } + /** Alias for calling [functionData] with `FunctionData.ofPrompt(prompt)`. */ + fun functionData(prompt: FunctionData.Prompt) = + functionData(FunctionData.ofPrompt(prompt)) - /** The prompt, model, and its parameters */ - fun promptData(promptData: PromptData?) = apply { body.promptData(promptData) } + /** Alias for calling [functionData] with `FunctionData.ofCode(code)`. */ + fun functionData(code: FunctionData.Code) = functionData(FunctionData.ofCode(code)) - /** Alias for calling [Builder.promptData] with `promptData.orElse(null)`. */ - fun promptData(promptData: Optional) = promptData(promptData.getOrNull()) + /** Alias for calling [functionData] with `FunctionData.ofGlobal(global)`. */ + fun functionData(global: FunctionData.Global) = + functionData(FunctionData.ofGlobal(global)) - /** - * Sets [Builder.promptData] to an arbitrary JSON value. - * - * You should usually call [Builder.promptData] with a well-typed [PromptData] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun promptData(promptData: JsonField) = apply { body.promptData(promptData) } + /** Name of the prompt */ + fun name(name: String) = name(JsonField.of(name)) - /** A list of tags for the prompt */ - fun tags(tags: List?) = apply { body.tags(tags) } + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } - /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ - fun tags(tags: Optional>) = tags(tags.getOrNull()) + /** Unique identifier for the project that the prompt belongs under */ + fun projectId(projectId: String) = projectId(JsonField.of(projectId)) - /** - * Sets [Builder.tags] to an arbitrary JSON value. - * - * You should usually call [Builder.tags] with a well-typed `List` value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun tags(tags: JsonField>) = apply { body.tags(tags) } + /** + * Sets [Builder.projectId] to an arbitrary JSON value. + * + * You should usually call [Builder.projectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun projectId(projectId: JsonField) = apply { this.projectId = projectId } - /** - * Adds a single [String] to [tags]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addTag(tag: String) = apply { body.addTag(tag) } + /** Unique identifier for the prompt */ + fun slug(slug: String) = slug(JsonField.of(slug)) - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) - } + /** + * Sets [Builder.slug] to an arbitrary JSON value. + * + * You should usually call [Builder.slug] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun slug(slug: JsonField) = apply { this.slug = slug } - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } + /** Textual description of the prompt */ + fun description(description: String?) = description(JsonField.ofNullable(description)) - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun description(description: JsonField) = apply { + this.description = description } - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + /** JSON schema for the function's parameters and return type */ + fun functionSchema(functionSchema: FunctionSchema?) = + functionSchema(JsonField.ofNullable(functionSchema)) - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } + /** Alias for calling [Builder.functionSchema] with `functionSchema.orElse(null)`. */ + fun functionSchema(functionSchema: Optional) = + functionSchema(functionSchema.getOrNull()) - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * Sets [Builder.functionSchema] to an arbitrary JSON value. + * + * You should usually call [Builder.functionSchema] with a well-typed [FunctionSchema] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun functionSchema(functionSchema: JsonField) = apply { + this.functionSchema = functionSchema + } - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + fun functionType(functionType: FunctionType?) = + functionType(JsonField.ofNullable(functionType)) - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } + /** Alias for calling [Builder.functionType] with `functionType.orElse(null)`. */ + fun functionType(functionType: Optional) = + functionType(functionType.getOrNull()) + + /** + * Sets [Builder.functionType] to an arbitrary JSON value. + * + * You should usually call [Builder.functionType] with a well-typed [FunctionType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun functionType(functionType: JsonField) = apply { + this.functionType = functionType + } - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } + fun origin(origin: Origin?) = origin(JsonField.ofNullable(origin)) - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** Alias for calling [Builder.origin] with `origin.orElse(null)`. */ + fun origin(origin: Optional) = origin(origin.getOrNull()) - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** + * Sets [Builder.origin] to an arbitrary JSON value. + * + * You should usually call [Builder.origin] with a well-typed [Origin] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun origin(origin: JsonField) = apply { this.origin = origin } - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } + /** The prompt, model, and its parameters */ + fun promptData(promptData: PromptData?) = promptData(JsonField.ofNullable(promptData)) - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } + /** Alias for calling [Builder.promptData] with `promptData.orElse(null)`. */ + fun promptData(promptData: Optional) = promptData(promptData.getOrNull()) - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** + * Sets [Builder.promptData] to an arbitrary JSON value. + * + * You should usually call [Builder.promptData] with a well-typed [PromptData] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun promptData(promptData: JsonField) = apply { + this.promptData = promptData + } - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** A list of tags for the prompt */ + fun tags(tags: List?) = tags(JsonField.ofNullable(tags)) - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ + fun tags(tags: Optional>) = tags(tags.getOrNull()) - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } + /** + * Sets [Builder.tags] to an arbitrary JSON value. + * + * You should usually call [Builder.tags] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tags(tags: JsonField>) = apply { + this.tags = tags.map { it.toMutableList() } + } - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + /** + * Adds a single [String] to [tags]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTag(tag: String) = apply { + tags = + (tags ?: JsonField.of(mutableListOf())).also { checkKnown("tags", it).add(tag) } + } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .functionData() + * .name() + * .projectId() + * .slug() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("functionData", functionData), + checkRequired("name", name), + checkRequired("projectId", projectId), + checkRequired("slug", slug), + description, + functionSchema, + functionType, + origin, + promptData, + (tags ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } + private var validated: Boolean = false - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + fun validate(): Body = apply { + if (validated) { + return@apply + } + + functionData().validate() + name() + projectId() + slug() + description() + functionSchema().ifPresent { it.validate() } + functionType() + origin().ifPresent { it.validate() } + promptData().ifPresent { it.validate() } + tags() + validated = true } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) + return /* spotless:off */ other is Body && functionData == other.functionData && name == other.name && projectId == other.projectId && slug == other.slug && description == other.description && functionSchema == other.functionSchema && functionType == other.functionType && origin == other.origin && promptData == other.promptData && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ } - /** - * Returns an immutable instance of [FunctionReplaceParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .functionData() - * .name() - * .projectId() - * .slug() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): FunctionReplaceParams = - FunctionReplaceParams( - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(functionData, name, projectId, slug, description, functionSchema, functionType, origin, promptData, tags, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{functionData=$functionData, name=$name, projectId=$projectId, slug=$slug, description=$description, functionSchema=$functionSchema, functionType=$functionType, origin=$origin, promptData=$promptData, tags=$tags, additionalProperties=$additionalProperties}" } @JsonDeserialize(using = FunctionData.Deserializer::class) @@ -1202,17 +1221,17 @@ private constructor( } } - @NoAutoDetect class Prompt - @JsonCreator private constructor( - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of() + ) : this(type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -1227,20 +1246,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Prompt = apply { - if (validated) { - return@apply - } - - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1315,7 +1329,18 @@ private constructor( * @throws IllegalStateException if any required field is unset. */ fun build(): Prompt = - Prompt(checkRequired("type", type), additionalProperties.toImmutable()) + Prompt(checkRequired("type", type), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Prompt = apply { + if (validated) { + return@apply + } + + type() + validated = true } class Type @JsonCreator private constructor(private val value: JsonField) : @@ -1433,20 +1458,19 @@ private constructor( "Prompt{type=$type, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Code - @JsonCreator private constructor( - @JsonProperty("data") - @ExcludeMissing - private val data: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val data: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(data, type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -1475,21 +1499,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Code = apply { - if (validated) { - return@apply - } - - data().validate() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1588,10 +1606,22 @@ private constructor( Code( checkRequired("data", data), checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Code = apply { + if (validated) { + return@apply + } + + data().validate() + type() + validated = true + } + @JsonDeserialize(using = Data.Deserializer::class) @JsonSerialize(using = Data.Serializer::class) class Data @@ -1728,30 +1758,43 @@ private constructor( } } - @NoAutoDetect class Bundle - @JsonCreator private constructor( - @JsonProperty("bundle_id") - @ExcludeMissing - private val bundleId: JsonField = JsonMissing.of(), - @JsonProperty("location") - @ExcludeMissing - private val location: JsonField = JsonMissing.of(), - @JsonProperty("runtime_context") - @ExcludeMissing - private val runtimeContext: JsonField = - JsonMissing.of(), - @JsonProperty("preview") - @ExcludeMissing - private val preview: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val bundleId: JsonField, + private val location: JsonField, + private val runtimeContext: JsonField, + private val preview: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("bundle_id") + @ExcludeMissing + bundleId: JsonField = JsonMissing.of(), + @JsonProperty("location") + @ExcludeMissing + location: JsonField = JsonMissing.of(), + @JsonProperty("runtime_context") + @ExcludeMissing + runtimeContext: JsonField = JsonMissing.of(), + @JsonProperty("preview") + @ExcludeMissing + preview: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + ) : this(bundleId, location, runtimeContext, preview, type, mutableMapOf()) + + fun toCodeBundle(): CodeBundle = + CodeBundle.builder() + .bundleId(bundleId) + .location(location) + .runtimeContext(runtimeContext) + .preview(preview) + .build() + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type or is unexpectedly missing or null (e.g. if the server responded with @@ -1838,32 +1881,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun toCodeBundle(): CodeBundle = - CodeBundle.builder() - .bundleId(bundleId) - .location(location) - .runtimeContext(runtimeContext) - .preview(preview) - .build() - - private var validated: Boolean = false - - fun validate(): Bundle = apply { - if (validated) { - return@apply - } - - bundleId() - location().validate() - runtimeContext().validate() - preview() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -2030,10 +2056,25 @@ private constructor( checkRequired("runtimeContext", runtimeContext), preview, checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Bundle = apply { + if (validated) { + return@apply + } + + bundleId() + location().validate() + runtimeContext().validate() + preview() + type() + validated = true + } + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2153,23 +2194,27 @@ private constructor( "Bundle{bundleId=$bundleId, location=$location, runtimeContext=$runtimeContext, preview=$preview, type=$type, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Inline - @JsonCreator private constructor( - @JsonProperty("code") - @ExcludeMissing - private val code: JsonField = JsonMissing.of(), - @JsonProperty("runtime_context") - @ExcludeMissing - private val runtimeContext: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val code: JsonField, + private val runtimeContext: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("code") + @ExcludeMissing + code: JsonField = JsonMissing.of(), + @JsonProperty("runtime_context") + @ExcludeMissing + runtimeContext: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + ) : this(code, runtimeContext, type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type or is unexpectedly missing or null (e.g. if the server responded with @@ -2218,22 +2263,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Inline = apply { - if (validated) { - return@apply - } - - code() - runtimeContext().validate() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -2346,25 +2384,40 @@ private constructor( checkRequired("code", code), checkRequired("runtimeContext", runtimeContext), checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } - @NoAutoDetect + private var validated: Boolean = false + + fun validate(): Inline = apply { + if (validated) { + return@apply + } + + code() + runtimeContext().validate() + type() + validated = true + } + class RuntimeContext - @JsonCreator private constructor( - @JsonProperty("runtime") - @ExcludeMissing - private val runtime: JsonField = JsonMissing.of(), - @JsonProperty("version") - @ExcludeMissing - private val version: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = - immutableEmptyMap(), + private val runtime: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("runtime") + @ExcludeMissing + runtime: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + version: JsonField = JsonMissing.of(), + ) : this(runtime, version, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an * unexpected type or is unexpectedly missing or null (e.g. if the server @@ -2399,21 +2452,15 @@ private constructor( @ExcludeMissing fun _version(): JsonField = version + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): RuntimeContext = apply { - if (validated) { - return@apply - } - - runtime() - version() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -2514,10 +2561,22 @@ private constructor( RuntimeContext( checkRequired("runtime", runtime), checkRequired("version", version), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): RuntimeContext = apply { + if (validated) { + return@apply + } + + runtime() + version() + validated = true + } + class Runtime @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2883,20 +2942,19 @@ private constructor( "Code{data=$data, type=$type, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Global - @JsonCreator private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val name: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(name, type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -2925,21 +2983,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Global = apply { - if (validated) { - return@apply - } - - name() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -3032,10 +3084,22 @@ private constructor( Global( checkRequired("name", name), checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Global = apply { + if (validated) { + return@apply + } + + name() + type() + validated = true + } + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -3153,35 +3217,32 @@ private constructor( } /** JSON schema for the function's parameters and return type */ - @NoAutoDetect class FunctionSchema - @JsonCreator private constructor( - @JsonProperty("parameters") - @ExcludeMissing - private val parameters: JsonValue = JsonMissing.of(), - @JsonProperty("returns") @ExcludeMissing private val returns: JsonValue = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val parameters: JsonValue, + private val returns: JsonValue, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("parameters") @ExcludeMissing parameters: JsonValue = JsonMissing.of(), + @JsonProperty("returns") @ExcludeMissing returns: JsonValue = JsonMissing.of(), + ) : this(parameters, returns, mutableMapOf()) + @JsonProperty("parameters") @ExcludeMissing fun _parameters(): JsonValue = parameters @JsonProperty("returns") @ExcludeMissing fun _returns(): JsonValue = returns + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): FunctionSchema = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -3234,7 +3295,17 @@ private constructor( * Further updates to this [Builder] will not mutate the returned instance. */ fun build(): FunctionSchema = - FunctionSchema(parameters, returns, additionalProperties.toImmutable()) + FunctionSchema(parameters, returns, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): FunctionSchema = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { @@ -3370,23 +3441,27 @@ private constructor( override fun toString() = value.toString() } - @NoAutoDetect class Origin - @JsonCreator private constructor( - @JsonProperty("object_id") - @ExcludeMissing - private val objectId: JsonField = JsonMissing.of(), - @JsonProperty("object_type") - @ExcludeMissing - private val objectType: JsonField = JsonMissing.of(), - @JsonProperty("internal") - @ExcludeMissing - private val internal_: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val objectId: JsonField, + private val objectType: JsonField, + private val internal_: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("object_id") + @ExcludeMissing + objectId: JsonField = JsonMissing.of(), + @JsonProperty("object_type") + @ExcludeMissing + objectType: JsonField = JsonMissing.of(), + @JsonProperty("internal") + @ExcludeMissing + internal_: JsonField = JsonMissing.of(), + ) : this(objectId, objectType, internal_, mutableMapOf()) + /** * Id of the object the function is originating from * @@ -3435,22 +3510,15 @@ private constructor( */ @JsonProperty("internal") @ExcludeMissing fun _internal_(): JsonField = internal_ + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Origin = apply { - if (validated) { - return@apply - } - - objectId() - objectType() - internal_() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -3572,10 +3640,23 @@ private constructor( checkRequired("objectId", objectId), checkRequired("objectType", objectType), internal_, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Origin = apply { + if (validated) { + return@apply + } + + objectId() + objectType() + internal_() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionRetrieveParams.kt index cf034800..17d1b879 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionRetrieveParams.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers @@ -24,16 +23,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _pathParam(index: Int): String = - when (index) { - 0 -> functionId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - fun toBuilder() = Builder().from(this) companion object { @@ -50,7 +39,6 @@ private constructor( } /** A builder for [FunctionRetrieveParams]. */ - @NoAutoDetect class Builder internal constructor() { private var functionId: String? = null @@ -185,6 +173,16 @@ private constructor( ) } + fun _pathParam(index: Int): String = + when (index) { + 0 -> functionId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt index 18729399..280402c1 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt @@ -9,14 +9,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.models.CodeBundle.* @@ -31,6 +29,7 @@ import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -130,190 +129,447 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body + fun toBuilder() = Builder().from(this) - fun _pathParam(index: Int): String = - when (index) { - 0 -> functionId - else -> "" + companion object { + + /** + * Returns a mutable builder for constructing an instance of [FunctionUpdateParams]. + * + * The following fields are required: + * ```java + * .functionId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [FunctionUpdateParams]. */ + class Builder internal constructor() { + + private var functionId: String? = null + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(functionUpdateParams: FunctionUpdateParams) = apply { + functionId = functionUpdateParams.functionId + body = functionUpdateParams.body.toBuilder() + additionalHeaders = functionUpdateParams.additionalHeaders.toBuilder() + additionalQueryParams = functionUpdateParams.additionalQueryParams.toBuilder() } - override fun _headers(): Headers = additionalHeaders + /** Function id */ + fun functionId(functionId: String) = apply { this.functionId = functionId } - override fun _queryParams(): QueryParams = additionalQueryParams + /** Textual description of the prompt */ + fun description(description: String?) = apply { body.description(description) } - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("function_data") - @ExcludeMissing - private val functionData: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("prompt_data") - @ExcludeMissing - private val promptData: JsonField = JsonMissing.of(), - @JsonProperty("tags") - @ExcludeMissing - private val tags: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) /** - * Textual description of the prompt + * Sets [Builder.description] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(description: JsonField) = apply { body.description(description) } - /** - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun functionData(): Optional = - Optional.ofNullable(functionData.getNullable("function_data")) + fun functionData(functionData: FunctionData?) = apply { body.functionData(functionData) } - /** - * Name of the prompt - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + /** Alias for calling [Builder.functionData] with `functionData.orElse(null)`. */ + fun functionData(functionData: Optional) = + functionData(functionData.getOrNull()) /** - * The prompt, model, and its parameters + * Sets [Builder.functionData] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.functionData] with a well-typed [FunctionData] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun promptData(): Optional = - Optional.ofNullable(promptData.getNullable("prompt_data")) + fun functionData(functionData: JsonField) = apply { + body.functionData(functionData) + } - /** - * A list of tags for the prompt - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) + /** Alias for calling [functionData] with `FunctionData.ofPrompt(prompt)`. */ + fun functionData(prompt: FunctionData.Prompt) = apply { body.functionData(prompt) } - /** - * Returns the raw JSON value of [description]. - * - * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("description") - @ExcludeMissing - fun _description(): JsonField = description + /** Alias for calling [functionData] with `FunctionData.ofCode(code)`. */ + fun functionData(code: FunctionData.Code) = apply { body.functionData(code) } + + /** Alias for calling [functionData] with `FunctionData.ofGlobal(global)`. */ + fun functionData(global: FunctionData.Global) = apply { body.functionData(global) } + + /** Name of the prompt */ + fun name(name: String?) = apply { body.name(name) } + + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) /** - * Returns the raw JSON value of [functionData]. + * Sets [Builder.name] to an arbitrary JSON value. * - * Unlike [functionData], this method doesn't throw if the JSON field has an unexpected - * type. + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("function_data") - @ExcludeMissing - fun _functionData(): JsonField = functionData + fun name(name: JsonField) = apply { body.name(name) } + + /** The prompt, model, and its parameters */ + fun promptData(promptData: PromptData?) = apply { body.promptData(promptData) } + + /** Alias for calling [Builder.promptData] with `promptData.orElse(null)`. */ + fun promptData(promptData: Optional) = promptData(promptData.getOrNull()) /** - * Returns the raw JSON value of [name]. + * Sets [Builder.promptData] to an arbitrary JSON value. * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.promptData] with a well-typed [PromptData] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + fun promptData(promptData: JsonField) = apply { body.promptData(promptData) } + + /** A list of tags for the prompt */ + fun tags(tags: List?) = apply { body.tags(tags) } + + /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ + fun tags(tags: Optional>) = tags(tags.getOrNull()) /** - * Returns the raw JSON value of [promptData]. + * Sets [Builder.tags] to an arbitrary JSON value. * - * Unlike [promptData], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.tags] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("prompt_data") - @ExcludeMissing - fun _promptData(): JsonField = promptData + fun tags(tags: JsonField>) = apply { body.tags(tags) } /** - * Returns the raw JSON value of [tags]. + * Adds a single [String] to [tags]. * - * Unlike [tags], this method doesn't throw if the JSON field has an unexpected type. + * @throws IllegalStateException if the field was previously set to a non-list. */ - @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags + fun addTag(tag: String) = apply { body.addTag(tag) } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } - private var validated: Boolean = false + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } - fun validate(): Body = apply { - if (validated) { - return@apply + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) } - description() - functionData().ifPresent { it.validate() } - name() - promptData().ifPresent { it.validate() } - tags() - validated = true + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) } - fun toBuilder() = Builder().from(this) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - companion object { + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** Returns a mutable builder for constructing an instance of [Body]. */ - @JvmStatic fun builder() = Builder() + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - /** A builder for [Body]. */ - class Builder internal constructor() { + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - private var description: JsonField = JsonMissing.of() - private var functionData: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var promptData: JsonField = JsonMissing.of() - private var tags: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - @JvmSynthetic - internal fun from(body: Body) = apply { - description = body.description - functionData = body.functionData - name = body.name - promptData = body.promptData - tags = body.tags.map { it.toMutableList() } - additionalProperties = body.additionalProperties.toMutableMap() - } + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** Textual description of the prompt */ - fun description(description: String?) = description(JsonField.ofNullable(description)) + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun description(description: JsonField) = apply { - this.description = description - } + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - fun functionData(functionData: FunctionData?) = - functionData(JsonField.ofNullable(functionData)) + 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) + } + + /** + * Returns an immutable instance of [FunctionUpdateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .functionId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): FunctionUpdateParams = + FunctionUpdateParams( + checkRequired("functionId", functionId), + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + @JvmSynthetic internal fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> functionId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val description: JsonField, + private val functionData: JsonField, + private val name: JsonField, + private val promptData: JsonField, + private val tags: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("function_data") + @ExcludeMissing + functionData: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("prompt_data") + @ExcludeMissing + promptData: JsonField = JsonMissing.of(), + @JsonProperty("tags") @ExcludeMissing tags: JsonField> = JsonMissing.of(), + ) : this(description, functionData, name, promptData, tags, mutableMapOf()) + + /** + * Textual description of the prompt + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun description(): Optional = + Optional.ofNullable(description.getNullable("description")) + + /** + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun functionData(): Optional = + Optional.ofNullable(functionData.getNullable("function_data")) + + /** + * Name of the prompt + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + /** + * The prompt, model, and its parameters + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun promptData(): Optional = + Optional.ofNullable(promptData.getNullable("prompt_data")) + + /** + * A list of tags for the prompt + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [functionData]. + * + * Unlike [functionData], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("function_data") + @ExcludeMissing + fun _functionData(): JsonField = functionData + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [promptData]. + * + * Unlike [promptData], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("prompt_data") + @ExcludeMissing + fun _promptData(): JsonField = promptData + + /** + * Returns the raw JSON value of [tags]. + * + * Unlike [tags], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Body]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var description: JsonField = JsonMissing.of() + private var functionData: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var promptData: JsonField = JsonMissing.of() + private var tags: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + description = body.description + functionData = body.functionData + name = body.name + promptData = body.promptData + tags = body.tags.map { it.toMutableList() } + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** Textual description of the prompt */ + fun description(description: String?) = description(JsonField.ofNullable(description)) + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } + + fun functionData(functionData: FunctionData?) = + functionData(JsonField.ofNullable(functionData)) /** Alias for calling [Builder.functionData] with `functionData.orElse(null)`. */ fun functionData(functionData: Optional) = @@ -431,291 +687,41 @@ private constructor( name, promptData, (tags ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply } - return /* spotless:off */ other is Body && description == other.description && functionData == other.functionData && name == other.name && promptData == other.promptData && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ + description() + functionData().ifPresent { it.validate() } + name() + promptData().ifPresent { it.validate() } + tags() + validated = true } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(description, functionData, name, promptData, tags, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Body{description=$description, functionData=$functionData, name=$name, promptData=$promptData, tags=$tags, additionalProperties=$additionalProperties}" - } - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [FunctionUpdateParams]. - * - * The following fields are required: - * ```java - * .functionId() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [FunctionUpdateParams]. */ - @NoAutoDetect - class Builder internal constructor() { - - private var functionId: String? = null - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - - @JvmSynthetic - internal fun from(functionUpdateParams: FunctionUpdateParams) = apply { - functionId = functionUpdateParams.functionId - body = functionUpdateParams.body.toBuilder() - additionalHeaders = functionUpdateParams.additionalHeaders.toBuilder() - additionalQueryParams = functionUpdateParams.additionalQueryParams.toBuilder() - } - - /** Function id */ - fun functionId(functionId: String) = apply { this.functionId = functionId } - - /** Textual description of the prompt */ - fun description(description: String?) = apply { body.description(description) } - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) - - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun description(description: JsonField) = apply { body.description(description) } - - fun functionData(functionData: FunctionData?) = apply { body.functionData(functionData) } - - /** Alias for calling [Builder.functionData] with `functionData.orElse(null)`. */ - fun functionData(functionData: Optional) = - functionData(functionData.getOrNull()) - - /** - * Sets [Builder.functionData] to an arbitrary JSON value. - * - * You should usually call [Builder.functionData] with a well-typed [FunctionData] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun functionData(functionData: JsonField) = apply { - body.functionData(functionData) - } - - /** Alias for calling [functionData] with `FunctionData.ofPrompt(prompt)`. */ - fun functionData(prompt: FunctionData.Prompt) = apply { body.functionData(prompt) } - - /** Alias for calling [functionData] with `FunctionData.ofCode(code)`. */ - fun functionData(code: FunctionData.Code) = apply { body.functionData(code) } - - /** Alias for calling [functionData] with `FunctionData.ofGlobal(global)`. */ - fun functionData(global: FunctionData.Global) = apply { body.functionData(global) } - - /** Name of the prompt */ - fun name(name: String?) = apply { body.name(name) } - - /** Alias for calling [Builder.name] with `name.orElse(null)`. */ - fun name(name: Optional) = name(name.getOrNull()) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun name(name: JsonField) = apply { body.name(name) } - - /** The prompt, model, and its parameters */ - fun promptData(promptData: PromptData?) = apply { body.promptData(promptData) } - - /** Alias for calling [Builder.promptData] with `promptData.orElse(null)`. */ - fun promptData(promptData: Optional) = promptData(promptData.getOrNull()) - - /** - * Sets [Builder.promptData] to an arbitrary JSON value. - * - * You should usually call [Builder.promptData] with a well-typed [PromptData] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun promptData(promptData: JsonField) = apply { body.promptData(promptData) } - - /** A list of tags for the prompt */ - fun tags(tags: List?) = apply { body.tags(tags) } - - /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ - fun tags(tags: Optional>) = tags(tags.getOrNull()) - - /** - * Sets [Builder.tags] to an arbitrary JSON value. - * - * You should usually call [Builder.tags] with a well-typed `List` value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun tags(tags: JsonField>) = apply { body.tags(tags) } - - /** - * Adds a single [String] to [tags]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addTag(tag: String) = apply { body.addTag(tag) } - - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) - } - - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } - - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) - } - - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } - - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } - - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } - - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(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 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) - } - - /** - * Returns an immutable instance of [FunctionUpdateParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .functionId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): FunctionUpdateParams = - FunctionUpdateParams( - checkRequired("functionId", functionId), - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && description == other.description && functionData == other.functionData && name == other.name && promptData == other.promptData && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(description, functionData, name, promptData, tags, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{description=$description, functionData=$functionData, name=$name, promptData=$promptData, tags=$tags, additionalProperties=$additionalProperties}" } @JsonDeserialize(using = FunctionData.Deserializer::class) @@ -876,17 +882,17 @@ private constructor( } } - @NoAutoDetect class Prompt - @JsonCreator private constructor( - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of() + ) : this(type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -901,20 +907,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Prompt = apply { - if (validated) { - return@apply - } - - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -989,7 +990,18 @@ private constructor( * @throws IllegalStateException if any required field is unset. */ fun build(): Prompt = - Prompt(checkRequired("type", type), additionalProperties.toImmutable()) + Prompt(checkRequired("type", type), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Prompt = apply { + if (validated) { + return@apply + } + + type() + validated = true } class Type @JsonCreator private constructor(private val value: JsonField) : @@ -1107,20 +1119,19 @@ private constructor( "Prompt{type=$type, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Code - @JsonCreator private constructor( - @JsonProperty("data") - @ExcludeMissing - private val data: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val data: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(data, type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -1149,21 +1160,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Code = apply { - if (validated) { - return@apply - } - - data().validate() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1262,10 +1267,22 @@ private constructor( Code( checkRequired("data", data), checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Code = apply { + if (validated) { + return@apply + } + + data().validate() + type() + validated = true + } + @JsonDeserialize(using = Data.Deserializer::class) @JsonSerialize(using = Data.Serializer::class) class Data @@ -1402,30 +1419,43 @@ private constructor( } } - @NoAutoDetect class Bundle - @JsonCreator private constructor( - @JsonProperty("bundle_id") - @ExcludeMissing - private val bundleId: JsonField = JsonMissing.of(), - @JsonProperty("location") - @ExcludeMissing - private val location: JsonField = JsonMissing.of(), - @JsonProperty("runtime_context") - @ExcludeMissing - private val runtimeContext: JsonField = - JsonMissing.of(), - @JsonProperty("preview") - @ExcludeMissing - private val preview: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val bundleId: JsonField, + private val location: JsonField, + private val runtimeContext: JsonField, + private val preview: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("bundle_id") + @ExcludeMissing + bundleId: JsonField = JsonMissing.of(), + @JsonProperty("location") + @ExcludeMissing + location: JsonField = JsonMissing.of(), + @JsonProperty("runtime_context") + @ExcludeMissing + runtimeContext: JsonField = JsonMissing.of(), + @JsonProperty("preview") + @ExcludeMissing + preview: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + ) : this(bundleId, location, runtimeContext, preview, type, mutableMapOf()) + + fun toCodeBundle(): CodeBundle = + CodeBundle.builder() + .bundleId(bundleId) + .location(location) + .runtimeContext(runtimeContext) + .preview(preview) + .build() + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type or is unexpectedly missing or null (e.g. if the server responded with @@ -1512,32 +1542,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun toCodeBundle(): CodeBundle = - CodeBundle.builder() - .bundleId(bundleId) - .location(location) - .runtimeContext(runtimeContext) - .preview(preview) - .build() - - private var validated: Boolean = false - - fun validate(): Bundle = apply { - if (validated) { - return@apply - } - - bundleId() - location().validate() - runtimeContext().validate() - preview() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1704,10 +1717,25 @@ private constructor( checkRequired("runtimeContext", runtimeContext), preview, checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Bundle = apply { + if (validated) { + return@apply + } + + bundleId() + location().validate() + runtimeContext().validate() + preview() + type() + validated = true + } + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -1827,23 +1855,27 @@ private constructor( "Bundle{bundleId=$bundleId, location=$location, runtimeContext=$runtimeContext, preview=$preview, type=$type, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Inline - @JsonCreator private constructor( - @JsonProperty("code") - @ExcludeMissing - private val code: JsonField = JsonMissing.of(), - @JsonProperty("runtime_context") - @ExcludeMissing - private val runtimeContext: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val code: JsonField, + private val runtimeContext: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("code") + @ExcludeMissing + code: JsonField = JsonMissing.of(), + @JsonProperty("runtime_context") + @ExcludeMissing + runtimeContext: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + ) : this(code, runtimeContext, type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type or is unexpectedly missing or null (e.g. if the server responded with @@ -1892,22 +1924,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Inline = apply { - if (validated) { - return@apply - } - - code() - runtimeContext().validate() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -2020,25 +2045,40 @@ private constructor( checkRequired("code", code), checkRequired("runtimeContext", runtimeContext), checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } - @NoAutoDetect + private var validated: Boolean = false + + fun validate(): Inline = apply { + if (validated) { + return@apply + } + + code() + runtimeContext().validate() + type() + validated = true + } + class RuntimeContext - @JsonCreator private constructor( - @JsonProperty("runtime") - @ExcludeMissing - private val runtime: JsonField = JsonMissing.of(), - @JsonProperty("version") - @ExcludeMissing - private val version: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = - immutableEmptyMap(), + private val runtime: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("runtime") + @ExcludeMissing + runtime: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + version: JsonField = JsonMissing.of(), + ) : this(runtime, version, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an * unexpected type or is unexpectedly missing or null (e.g. if the server @@ -2073,21 +2113,15 @@ private constructor( @ExcludeMissing fun _version(): JsonField = version + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): RuntimeContext = apply { - if (validated) { - return@apply - } - - runtime() - version() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -2188,10 +2222,22 @@ private constructor( RuntimeContext( checkRequired("runtime", runtime), checkRequired("version", version), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): RuntimeContext = apply { + if (validated) { + return@apply + } + + runtime() + version() + validated = true + } + class Runtime @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2557,20 +2603,19 @@ private constructor( "Code{data=$data, type=$type, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Global - @JsonCreator private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val name: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(name, type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -2599,21 +2644,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Global = apply { - if (validated) { - return@apply - } - - name() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -2706,10 +2745,22 @@ private constructor( Global( checkRequired("name", name), checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Global = apply { + if (validated) { + return@apply + } + + name() + type() + validated = true + } + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Group.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Group.kt index 4ab379e6..a81249f1 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Group.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Group.kt @@ -6,10 +6,8 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter @@ -17,6 +15,7 @@ import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -26,34 +25,54 @@ import kotlin.jvm.optionals.getOrNull * * Groups can consist of individual users, as well as a set of groups they inherit from */ -@NoAutoDetect class Group -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing private val name: JsonField = JsonMissing.of(), - @JsonProperty("org_id") @ExcludeMissing private val orgId: JsonField = JsonMissing.of(), - @JsonProperty("created") - @ExcludeMissing - private val created: JsonField = JsonMissing.of(), - @JsonProperty("deleted_at") - @ExcludeMissing - private val deletedAt: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("member_groups") - @ExcludeMissing - private val memberGroups: JsonField> = JsonMissing.of(), - @JsonProperty("member_users") - @ExcludeMissing - private val memberUsers: JsonField> = JsonMissing.of(), - @JsonProperty("user_id") - @ExcludeMissing - private val userId: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val name: JsonField, + private val orgId: JsonField, + private val created: JsonField, + private val deletedAt: JsonField, + private val description: JsonField, + private val memberGroups: JsonField>, + private val memberUsers: JsonField>, + private val userId: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("org_id") @ExcludeMissing orgId: JsonField = JsonMissing.of(), + @JsonProperty("created") + @ExcludeMissing + created: JsonField = JsonMissing.of(), + @JsonProperty("deleted_at") + @ExcludeMissing + deletedAt: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("member_groups") + @ExcludeMissing + memberGroups: JsonField> = JsonMissing.of(), + @JsonProperty("member_users") + @ExcludeMissing + memberUsers: JsonField> = JsonMissing.of(), + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), + ) : this( + id, + name, + orgId, + created, + deletedAt, + description, + memberGroups, + memberUsers, + userId, + mutableMapOf(), + ) + /** * Unique identifier for the group * @@ -204,28 +223,15 @@ private constructor( */ @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Group = apply { - if (validated) { - return@apply - } - - id() - name() - orgId() - created() - deletedAt() - description() - memberGroups() - memberUsers() - userId() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -477,10 +483,29 @@ private constructor( (memberGroups ?: JsonMissing.of()).map { it.toImmutable() }, (memberUsers ?: JsonMissing.of()).map { it.toImmutable() }, userId, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Group = apply { + if (validated) { + return@apply + } + + id() + name() + orgId() + created() + deletedAt() + description() + memberGroups() + memberUsers() + userId() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupCreateParams.kt index cda2eae4..410b148e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupCreateParams.kt @@ -6,19 +6,18 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -120,205 +119,462 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body + fun toBuilder() = Builder().from(this) - override fun _headers(): Headers = additionalHeaders + companion object { - override fun _queryParams(): QueryParams = additionalQueryParams + /** + * Returns a mutable builder for constructing an instance of [GroupCreateParams]. + * + * The following fields are required: + * ```java + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("member_groups") - @ExcludeMissing - private val memberGroups: JsonField> = JsonMissing.of(), - @JsonProperty("member_users") - @ExcludeMissing - private val memberUsers: JsonField> = JsonMissing.of(), - @JsonProperty("org_name") - @ExcludeMissing - private val orgName: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + /** A builder for [GroupCreateParams]. */ + class Builder internal constructor() { + + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(groupCreateParams: GroupCreateParams) = apply { + body = groupCreateParams.body.toBuilder() + additionalHeaders = groupCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = groupCreateParams.additionalQueryParams.toBuilder() + } + + /** Name of the group */ + fun name(name: String) = apply { body.name(name) } /** - * Name of the group + * Sets [Builder.name] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun name(): String = name.getRequired("name") + fun name(name: JsonField) = apply { body.name(name) } + + /** Textual description of the group */ + fun description(description: String?) = apply { body.description(description) } + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) /** - * Textual description of the group + * Sets [Builder.description] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(description: JsonField) = apply { body.description(description) } /** * Ids of the groups this group inherits from * * An inheriting group has all the users contained in its member groups, as well as all of * their inherited users - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). */ - fun memberGroups(): Optional> = - Optional.ofNullable(memberGroups.getNullable("member_groups")) + fun memberGroups(memberGroups: List?) = apply { body.memberGroups(memberGroups) } - /** - * Ids of users which belong to this group - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun memberUsers(): Optional> = - Optional.ofNullable(memberUsers.getNullable("member_users")) + /** Alias for calling [Builder.memberGroups] with `memberGroups.orElse(null)`. */ + fun memberGroups(memberGroups: Optional>) = + memberGroups(memberGroups.getOrNull()) /** - * For nearly all users, this parameter should be unnecessary. But in the rare case that - * your API key belongs to multiple organizations, you may specify the name of the - * organization the group belongs in. + * Sets [Builder.memberGroups] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.memberGroups] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) + fun memberGroups(memberGroups: JsonField>) = apply { + body.memberGroups(memberGroups) + } /** - * Returns the raw JSON value of [name]. + * Adds a single [String] to [memberGroups]. * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + * @throws IllegalStateException if the field was previously set to a non-list. */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + fun addMemberGroup(memberGroup: String) = apply { body.addMemberGroup(memberGroup) } + + /** Ids of users which belong to this group */ + fun memberUsers(memberUsers: List?) = apply { body.memberUsers(memberUsers) } + + /** Alias for calling [Builder.memberUsers] with `memberUsers.orElse(null)`. */ + fun memberUsers(memberUsers: Optional>) = memberUsers(memberUsers.getOrNull()) /** - * Returns the raw JSON value of [description]. + * Sets [Builder.memberUsers] to an arbitrary JSON value. * - * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.memberUsers] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("description") - @ExcludeMissing - fun _description(): JsonField = description + fun memberUsers(memberUsers: JsonField>) = apply { + body.memberUsers(memberUsers) + } /** - * Returns the raw JSON value of [memberGroups]. + * Adds a single [String] to [memberUsers]. * - * Unlike [memberGroups], this method doesn't throw if the JSON field has an unexpected - * type. + * @throws IllegalStateException if the field was previously set to a non-list. */ - @JsonProperty("member_groups") - @ExcludeMissing - fun _memberGroups(): JsonField> = memberGroups + fun addMemberUser(memberUser: String) = apply { body.addMemberUser(memberUser) } /** - * Returns the raw JSON value of [memberUsers]. - * - * Unlike [memberUsers], this method doesn't throw if the JSON field has an unexpected type. + * For nearly all users, this parameter should be unnecessary. But in the rare case that + * your API key belongs to multiple organizations, you may specify the name of the + * organization the group belongs in. */ - @JsonProperty("member_users") - @ExcludeMissing - fun _memberUsers(): JsonField> = memberUsers + fun orgName(orgName: String?) = apply { body.orgName(orgName) } + + /** Alias for calling [Builder.orgName] with `orgName.orElse(null)`. */ + fun orgName(orgName: Optional) = orgName(orgName.getOrNull()) /** - * Returns the raw JSON value of [orgName]. + * Sets [Builder.orgName] to an arbitrary JSON value. * - * Unlike [orgName], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.orgName] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("org_name") @ExcludeMissing fun _orgName(): JsonField = orgName + fun orgName(orgName: JsonField) = apply { body.orgName(orgName) } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } - private var validated: Boolean = false + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } - fun validate(): Body = apply { - if (validated) { - return@apply + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) } - name() - description() - memberGroups() - memberUsers() - orgName() - validated = true + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) } - fun toBuilder() = Builder().from(this) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - companion object { + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .name() - * ``` - */ - @JvmStatic fun builder() = Builder() + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - /** A builder for [Body]. */ - class Builder internal constructor() { + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - private var name: JsonField? = null - private var description: JsonField = JsonMissing.of() - private var memberGroups: JsonField>? = null - private var memberUsers: JsonField>? = null - private var orgName: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - @JvmSynthetic - internal fun from(body: Body) = apply { - name = body.name - description = body.description - memberGroups = body.memberGroups.map { it.toMutableList() } - memberUsers = body.memberUsers.map { it.toMutableList() } - orgName = body.orgName - additionalProperties = body.additionalProperties.toMutableMap() - } + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** Name of the group */ - fun name(name: String) = name(JsonField.of(name)) + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** Textual description of the group */ - fun description(description: String?) = description(JsonField.ofNullable(description)) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun description(description: JsonField) = apply { + 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) + } + + /** + * Returns an immutable instance of [GroupCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupCreateParams = + GroupCreateParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + @JvmSynthetic internal fun _body(): Body = body + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val name: JsonField, + private val description: JsonField, + private val memberGroups: JsonField>, + private val memberUsers: JsonField>, + private val orgName: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("member_groups") + @ExcludeMissing + memberGroups: JsonField> = JsonMissing.of(), + @JsonProperty("member_users") + @ExcludeMissing + memberUsers: JsonField> = JsonMissing.of(), + @JsonProperty("org_name") @ExcludeMissing orgName: JsonField = JsonMissing.of(), + ) : this(name, description, memberGroups, memberUsers, orgName, mutableMapOf()) + + /** + * Name of the group + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * Textual description of the group + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun description(): Optional = + Optional.ofNullable(description.getNullable("description")) + + /** + * Ids of the groups this group inherits from + * + * An inheriting group has all the users contained in its member groups, as well as all of + * their inherited users + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun memberGroups(): Optional> = + Optional.ofNullable(memberGroups.getNullable("member_groups")) + + /** + * Ids of users which belong to this group + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun memberUsers(): Optional> = + Optional.ofNullable(memberUsers.getNullable("member_users")) + + /** + * For nearly all users, this parameter should be unnecessary. But in the rare case that + * your API key belongs to multiple organizations, you may specify the name of the + * organization the group belongs in. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [memberGroups]. + * + * Unlike [memberGroups], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("member_groups") + @ExcludeMissing + fun _memberGroups(): JsonField> = memberGroups + + /** + * Returns the raw JSON value of [memberUsers]. + * + * Unlike [memberUsers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("member_users") + @ExcludeMissing + fun _memberUsers(): JsonField> = memberUsers + + /** + * Returns the raw JSON value of [orgName]. + * + * Unlike [orgName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("org_name") @ExcludeMissing fun _orgName(): JsonField = orgName + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var name: JsonField? = null + private var description: JsonField = JsonMissing.of() + private var memberGroups: JsonField>? = null + private var memberUsers: JsonField>? = null + private var orgName: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + name = body.name + description = body.description + memberGroups = body.memberGroups.map { it.toMutableList() } + memberUsers = body.memberUsers.map { it.toMutableList() } + orgName = body.orgName + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** Name of the group */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** Textual description of the group */ + fun description(description: String?) = description(JsonField.ofNullable(description)) + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun description(description: JsonField) = apply { this.description = description } @@ -446,291 +702,41 @@ private constructor( (memberGroups ?: JsonMissing.of()).map { it.toImmutable() }, (memberUsers ?: JsonMissing.of()).map { it.toImmutable() }, orgName, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + private var validated: Boolean = false - return /* spotless:off */ other is Body && name == other.name && description == other.description && memberGroups == other.memberGroups && memberUsers == other.memberUsers && orgName == other.orgName && additionalProperties == other.additionalProperties /* spotless:on */ - } + fun validate(): Body = apply { + if (validated) { + return@apply + } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, description, memberGroups, memberUsers, orgName, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Body{name=$name, description=$description, memberGroups=$memberGroups, memberUsers=$memberUsers, orgName=$orgName, additionalProperties=$additionalProperties}" - } - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [GroupCreateParams]. - * - * The following fields are required: - * ```java - * .name() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [GroupCreateParams]. */ - @NoAutoDetect - class Builder internal constructor() { - - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - - @JvmSynthetic - internal fun from(groupCreateParams: GroupCreateParams) = apply { - body = groupCreateParams.body.toBuilder() - additionalHeaders = groupCreateParams.additionalHeaders.toBuilder() - additionalQueryParams = groupCreateParams.additionalQueryParams.toBuilder() - } - - /** Name of the group */ - fun name(name: String) = apply { body.name(name) } - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun name(name: JsonField) = apply { body.name(name) } - - /** Textual description of the group */ - fun description(description: String?) = apply { body.description(description) } - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) - - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun description(description: JsonField) = apply { body.description(description) } - - /** - * Ids of the groups this group inherits from - * - * An inheriting group has all the users contained in its member groups, as well as all of - * their inherited users - */ - fun memberGroups(memberGroups: List?) = apply { body.memberGroups(memberGroups) } - - /** Alias for calling [Builder.memberGroups] with `memberGroups.orElse(null)`. */ - fun memberGroups(memberGroups: Optional>) = - memberGroups(memberGroups.getOrNull()) - - /** - * Sets [Builder.memberGroups] to an arbitrary JSON value. - * - * You should usually call [Builder.memberGroups] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun memberGroups(memberGroups: JsonField>) = apply { - body.memberGroups(memberGroups) - } - - /** - * Adds a single [String] to [memberGroups]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addMemberGroup(memberGroup: String) = apply { body.addMemberGroup(memberGroup) } - - /** Ids of users which belong to this group */ - fun memberUsers(memberUsers: List?) = apply { body.memberUsers(memberUsers) } - - /** Alias for calling [Builder.memberUsers] with `memberUsers.orElse(null)`. */ - fun memberUsers(memberUsers: Optional>) = memberUsers(memberUsers.getOrNull()) - - /** - * Sets [Builder.memberUsers] to an arbitrary JSON value. - * - * You should usually call [Builder.memberUsers] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun memberUsers(memberUsers: JsonField>) = apply { - body.memberUsers(memberUsers) - } - - /** - * Adds a single [String] to [memberUsers]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addMemberUser(memberUser: String) = apply { body.addMemberUser(memberUser) } - - /** - * For nearly all users, this parameter should be unnecessary. But in the rare case that - * your API key belongs to multiple organizations, you may specify the name of the - * organization the group belongs in. - */ - fun orgName(orgName: String?) = apply { body.orgName(orgName) } - - /** Alias for calling [Builder.orgName] with `orgName.orElse(null)`. */ - fun orgName(orgName: Optional) = orgName(orgName.getOrNull()) - - /** - * Sets [Builder.orgName] to an arbitrary JSON value. - * - * You should usually call [Builder.orgName] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun orgName(orgName: JsonField) = apply { body.orgName(orgName) } - - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) - } - - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } - - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) - } - - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } - - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } - - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } - - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(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 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) + name() + description() + memberGroups() + memberUsers() + orgName() + validated = true } - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - 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) + return /* spotless:off */ other is Body && name == other.name && description == other.description && memberGroups == other.memberGroups && memberUsers == other.memberUsers && orgName == other.orgName && additionalProperties == other.additionalProperties /* spotless:on */ } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) - } - - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(name, description, memberGroups, memberUsers, orgName, additionalProperties) } + /* spotless:on */ - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) - } + override fun hashCode(): Int = hashCode - /** - * Returns an immutable instance of [GroupCreateParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): GroupCreateParams = - GroupCreateParams( - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + override fun toString() = + "Body{name=$name, description=$description, memberGroups=$memberGroups, memberUsers=$memberUsers, orgName=$orgName, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupDeleteParams.kt index 792f925d..7bc274cc 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupDeleteParams.kt @@ -2,13 +2,15 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.toImmutable +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import java.util.Collections import java.util.Objects import java.util.Optional @@ -18,7 +20,7 @@ private constructor( private val groupId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: Map, + private val additionalBodyProperties: MutableMap, ) : Params { /** Group id */ @@ -28,21 +30,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _additionalBodyProperties(): Map = additionalBodyProperties - - @JvmSynthetic - internal fun _body(): Optional> = - Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - - fun _pathParam(index: Int): String = - when (index) { - 0 -> groupId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders + @JsonAnySetter + private fun putAdditionalBodyProperty(key: String, value: JsonValue) { + additionalBodyProperties.put(key, value) + } - override fun _queryParams(): QueryParams = additionalQueryParams + @JsonAnyGetter + @ExcludeMissing + fun _additionalBodyProperties(): Map = + Collections.unmodifiableMap(additionalBodyProperties) fun toBuilder() = Builder().from(this) @@ -60,7 +56,6 @@ private constructor( } /** A builder for [GroupDeleteParams]. */ - @NoAutoDetect class Builder internal constructor() { private var groupId: String? = null @@ -216,10 +211,24 @@ private constructor( checkRequired("groupId", groupId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toImmutable(), + additionalBodyProperties.toMutableMap(), ) } + @JvmSynthetic + internal fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> groupId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt index 33debe68..4d64e639 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.blocking.GroupService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -81,23 +79,30 @@ private constructor( GroupListPage(groupsService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -155,7 +160,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt index 7b8849b1..59586a2c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.async.GroupServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -83,23 +81,30 @@ private constructor( GroupListPageAsync(groupsService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -157,7 +162,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListParams.kt index 94cc7e6a..9ab47c5c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListParams.kt @@ -5,7 +5,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.BaseDeserializer import com.braintrustdata.api.core.BaseSerializer import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers @@ -75,31 +74,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = - QueryParams.builder() - .apply { - endingBefore?.let { put("ending_before", it) } - groupName?.let { put("group_name", it) } - ids?.accept( - object : Ids.Visitor { - override fun visitString(string: String) { - put("ids", string) - } - - override fun visitStrings(strings: List) { - put("ids", strings.joinToString(",")) - } - } - ) - limit?.let { put("limit", it.toString()) } - orgName?.let { put("org_name", it) } - startingAfter?.let { put("starting_after", it) } - putAll(additionalQueryParams) - } - .build() - fun toBuilder() = Builder().from(this) companion object { @@ -111,7 +85,6 @@ private constructor( } /** A builder for [GroupListParams]. */ - @NoAutoDetect class Builder internal constructor() { private var endingBefore: String? = null @@ -316,6 +289,31 @@ private constructor( ) } + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + endingBefore?.let { put("ending_before", it) } + groupName?.let { put("group_name", it) } + ids?.accept( + object : Ids.Visitor { + override fun visitString(string: String) { + put("ids", string) + } + + override fun visitStrings(strings: List) { + put("ids", strings.joinToString(",")) + } + } + ) + limit?.let { put("limit", it.toString()) } + orgName?.let { put("org_name", it) } + startingAfter?.let { put("starting_after", it) } + putAll(additionalQueryParams) + } + .build() + /** * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupReplaceParams.kt index b11f2119..4ee6109f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupReplaceParams.kt @@ -6,19 +6,18 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -120,205 +119,462 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body + fun toBuilder() = Builder().from(this) - override fun _headers(): Headers = additionalHeaders + companion object { - override fun _queryParams(): QueryParams = additionalQueryParams + /** + * Returns a mutable builder for constructing an instance of [GroupReplaceParams]. + * + * The following fields are required: + * ```java + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("member_groups") - @ExcludeMissing - private val memberGroups: JsonField> = JsonMissing.of(), - @JsonProperty("member_users") - @ExcludeMissing - private val memberUsers: JsonField> = JsonMissing.of(), - @JsonProperty("org_name") - @ExcludeMissing - private val orgName: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + /** A builder for [GroupReplaceParams]. */ + class Builder internal constructor() { + + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(groupReplaceParams: GroupReplaceParams) = apply { + body = groupReplaceParams.body.toBuilder() + additionalHeaders = groupReplaceParams.additionalHeaders.toBuilder() + additionalQueryParams = groupReplaceParams.additionalQueryParams.toBuilder() + } + + /** Name of the group */ + fun name(name: String) = apply { body.name(name) } /** - * Name of the group + * Sets [Builder.name] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun name(): String = name.getRequired("name") + fun name(name: JsonField) = apply { body.name(name) } + + /** Textual description of the group */ + fun description(description: String?) = apply { body.description(description) } + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) /** - * Textual description of the group + * Sets [Builder.description] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(description: JsonField) = apply { body.description(description) } /** * Ids of the groups this group inherits from * * An inheriting group has all the users contained in its member groups, as well as all of * their inherited users - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). */ - fun memberGroups(): Optional> = - Optional.ofNullable(memberGroups.getNullable("member_groups")) + fun memberGroups(memberGroups: List?) = apply { body.memberGroups(memberGroups) } - /** - * Ids of users which belong to this group - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun memberUsers(): Optional> = - Optional.ofNullable(memberUsers.getNullable("member_users")) + /** Alias for calling [Builder.memberGroups] with `memberGroups.orElse(null)`. */ + fun memberGroups(memberGroups: Optional>) = + memberGroups(memberGroups.getOrNull()) /** - * For nearly all users, this parameter should be unnecessary. But in the rare case that - * your API key belongs to multiple organizations, you may specify the name of the - * organization the group belongs in. + * Sets [Builder.memberGroups] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.memberGroups] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) + fun memberGroups(memberGroups: JsonField>) = apply { + body.memberGroups(memberGroups) + } /** - * Returns the raw JSON value of [name]. + * Adds a single [String] to [memberGroups]. * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + * @throws IllegalStateException if the field was previously set to a non-list. */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + fun addMemberGroup(memberGroup: String) = apply { body.addMemberGroup(memberGroup) } + + /** Ids of users which belong to this group */ + fun memberUsers(memberUsers: List?) = apply { body.memberUsers(memberUsers) } + + /** Alias for calling [Builder.memberUsers] with `memberUsers.orElse(null)`. */ + fun memberUsers(memberUsers: Optional>) = memberUsers(memberUsers.getOrNull()) /** - * Returns the raw JSON value of [description]. + * Sets [Builder.memberUsers] to an arbitrary JSON value. * - * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.memberUsers] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("description") - @ExcludeMissing - fun _description(): JsonField = description + fun memberUsers(memberUsers: JsonField>) = apply { + body.memberUsers(memberUsers) + } /** - * Returns the raw JSON value of [memberGroups]. + * Adds a single [String] to [memberUsers]. * - * Unlike [memberGroups], this method doesn't throw if the JSON field has an unexpected - * type. + * @throws IllegalStateException if the field was previously set to a non-list. */ - @JsonProperty("member_groups") - @ExcludeMissing - fun _memberGroups(): JsonField> = memberGroups + fun addMemberUser(memberUser: String) = apply { body.addMemberUser(memberUser) } /** - * Returns the raw JSON value of [memberUsers]. - * - * Unlike [memberUsers], this method doesn't throw if the JSON field has an unexpected type. + * For nearly all users, this parameter should be unnecessary. But in the rare case that + * your API key belongs to multiple organizations, you may specify the name of the + * organization the group belongs in. */ - @JsonProperty("member_users") - @ExcludeMissing - fun _memberUsers(): JsonField> = memberUsers + fun orgName(orgName: String?) = apply { body.orgName(orgName) } + + /** Alias for calling [Builder.orgName] with `orgName.orElse(null)`. */ + fun orgName(orgName: Optional) = orgName(orgName.getOrNull()) /** - * Returns the raw JSON value of [orgName]. + * Sets [Builder.orgName] to an arbitrary JSON value. * - * Unlike [orgName], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.orgName] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("org_name") @ExcludeMissing fun _orgName(): JsonField = orgName + fun orgName(orgName: JsonField) = apply { body.orgName(orgName) } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } - private var validated: Boolean = false + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } - fun validate(): Body = apply { - if (validated) { - return@apply + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) } - name() - description() - memberGroups() - memberUsers() - orgName() - validated = true + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) } - fun toBuilder() = Builder().from(this) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - companion object { + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .name() - * ``` - */ - @JvmStatic fun builder() = Builder() + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - /** A builder for [Body]. */ - class Builder internal constructor() { + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - private var name: JsonField? = null - private var description: JsonField = JsonMissing.of() - private var memberGroups: JsonField>? = null - private var memberUsers: JsonField>? = null - private var orgName: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - @JvmSynthetic - internal fun from(body: Body) = apply { - name = body.name - description = body.description - memberGroups = body.memberGroups.map { it.toMutableList() } - memberUsers = body.memberUsers.map { it.toMutableList() } - orgName = body.orgName - additionalProperties = body.additionalProperties.toMutableMap() - } + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** Name of the group */ - fun name(name: String) = name(JsonField.of(name)) + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** Textual description of the group */ - fun description(description: String?) = description(JsonField.ofNullable(description)) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun description(description: JsonField) = apply { + 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) + } + + /** + * Returns an immutable instance of [GroupReplaceParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupReplaceParams = + GroupReplaceParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + @JvmSynthetic internal fun _body(): Body = body + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val name: JsonField, + private val description: JsonField, + private val memberGroups: JsonField>, + private val memberUsers: JsonField>, + private val orgName: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("member_groups") + @ExcludeMissing + memberGroups: JsonField> = JsonMissing.of(), + @JsonProperty("member_users") + @ExcludeMissing + memberUsers: JsonField> = JsonMissing.of(), + @JsonProperty("org_name") @ExcludeMissing orgName: JsonField = JsonMissing.of(), + ) : this(name, description, memberGroups, memberUsers, orgName, mutableMapOf()) + + /** + * Name of the group + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * Textual description of the group + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun description(): Optional = + Optional.ofNullable(description.getNullable("description")) + + /** + * Ids of the groups this group inherits from + * + * An inheriting group has all the users contained in its member groups, as well as all of + * their inherited users + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun memberGroups(): Optional> = + Optional.ofNullable(memberGroups.getNullable("member_groups")) + + /** + * Ids of users which belong to this group + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun memberUsers(): Optional> = + Optional.ofNullable(memberUsers.getNullable("member_users")) + + /** + * For nearly all users, this parameter should be unnecessary. But in the rare case that + * your API key belongs to multiple organizations, you may specify the name of the + * organization the group belongs in. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [memberGroups]. + * + * Unlike [memberGroups], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("member_groups") + @ExcludeMissing + fun _memberGroups(): JsonField> = memberGroups + + /** + * Returns the raw JSON value of [memberUsers]. + * + * Unlike [memberUsers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("member_users") + @ExcludeMissing + fun _memberUsers(): JsonField> = memberUsers + + /** + * Returns the raw JSON value of [orgName]. + * + * Unlike [orgName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("org_name") @ExcludeMissing fun _orgName(): JsonField = orgName + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var name: JsonField? = null + private var description: JsonField = JsonMissing.of() + private var memberGroups: JsonField>? = null + private var memberUsers: JsonField>? = null + private var orgName: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + name = body.name + description = body.description + memberGroups = body.memberGroups.map { it.toMutableList() } + memberUsers = body.memberUsers.map { it.toMutableList() } + orgName = body.orgName + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** Name of the group */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** Textual description of the group */ + fun description(description: String?) = description(JsonField.ofNullable(description)) + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun description(description: JsonField) = apply { this.description = description } @@ -446,291 +702,41 @@ private constructor( (memberGroups ?: JsonMissing.of()).map { it.toImmutable() }, (memberUsers ?: JsonMissing.of()).map { it.toImmutable() }, orgName, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + private var validated: Boolean = false - return /* spotless:off */ other is Body && name == other.name && description == other.description && memberGroups == other.memberGroups && memberUsers == other.memberUsers && orgName == other.orgName && additionalProperties == other.additionalProperties /* spotless:on */ - } + fun validate(): Body = apply { + if (validated) { + return@apply + } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, description, memberGroups, memberUsers, orgName, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Body{name=$name, description=$description, memberGroups=$memberGroups, memberUsers=$memberUsers, orgName=$orgName, additionalProperties=$additionalProperties}" - } - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [GroupReplaceParams]. - * - * The following fields are required: - * ```java - * .name() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [GroupReplaceParams]. */ - @NoAutoDetect - class Builder internal constructor() { - - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - - @JvmSynthetic - internal fun from(groupReplaceParams: GroupReplaceParams) = apply { - body = groupReplaceParams.body.toBuilder() - additionalHeaders = groupReplaceParams.additionalHeaders.toBuilder() - additionalQueryParams = groupReplaceParams.additionalQueryParams.toBuilder() - } - - /** Name of the group */ - fun name(name: String) = apply { body.name(name) } - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun name(name: JsonField) = apply { body.name(name) } - - /** Textual description of the group */ - fun description(description: String?) = apply { body.description(description) } - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) - - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun description(description: JsonField) = apply { body.description(description) } - - /** - * Ids of the groups this group inherits from - * - * An inheriting group has all the users contained in its member groups, as well as all of - * their inherited users - */ - fun memberGroups(memberGroups: List?) = apply { body.memberGroups(memberGroups) } - - /** Alias for calling [Builder.memberGroups] with `memberGroups.orElse(null)`. */ - fun memberGroups(memberGroups: Optional>) = - memberGroups(memberGroups.getOrNull()) - - /** - * Sets [Builder.memberGroups] to an arbitrary JSON value. - * - * You should usually call [Builder.memberGroups] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun memberGroups(memberGroups: JsonField>) = apply { - body.memberGroups(memberGroups) - } - - /** - * Adds a single [String] to [memberGroups]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addMemberGroup(memberGroup: String) = apply { body.addMemberGroup(memberGroup) } - - /** Ids of users which belong to this group */ - fun memberUsers(memberUsers: List?) = apply { body.memberUsers(memberUsers) } - - /** Alias for calling [Builder.memberUsers] with `memberUsers.orElse(null)`. */ - fun memberUsers(memberUsers: Optional>) = memberUsers(memberUsers.getOrNull()) - - /** - * Sets [Builder.memberUsers] to an arbitrary JSON value. - * - * You should usually call [Builder.memberUsers] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun memberUsers(memberUsers: JsonField>) = apply { - body.memberUsers(memberUsers) - } - - /** - * Adds a single [String] to [memberUsers]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addMemberUser(memberUser: String) = apply { body.addMemberUser(memberUser) } - - /** - * For nearly all users, this parameter should be unnecessary. But in the rare case that - * your API key belongs to multiple organizations, you may specify the name of the - * organization the group belongs in. - */ - fun orgName(orgName: String?) = apply { body.orgName(orgName) } - - /** Alias for calling [Builder.orgName] with `orgName.orElse(null)`. */ - fun orgName(orgName: Optional) = orgName(orgName.getOrNull()) - - /** - * Sets [Builder.orgName] to an arbitrary JSON value. - * - * You should usually call [Builder.orgName] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun orgName(orgName: JsonField) = apply { body.orgName(orgName) } - - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) - } - - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } - - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) - } - - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } - - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } - - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } - - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(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 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) + name() + description() + memberGroups() + memberUsers() + orgName() + validated = true } - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - 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) + return /* spotless:off */ other is Body && name == other.name && description == other.description && memberGroups == other.memberGroups && memberUsers == other.memberUsers && orgName == other.orgName && additionalProperties == other.additionalProperties /* spotless:on */ } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) - } - - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(name, description, memberGroups, memberUsers, orgName, additionalProperties) } + /* spotless:on */ - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) - } + override fun hashCode(): Int = hashCode - /** - * Returns an immutable instance of [GroupReplaceParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): GroupReplaceParams = - GroupReplaceParams( - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + override fun toString() = + "Body{name=$name, description=$description, memberGroups=$memberGroups, memberUsers=$memberUsers, orgName=$orgName, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupRetrieveParams.kt index 1e47d093..0134decd 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupRetrieveParams.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers @@ -24,16 +23,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _pathParam(index: Int): String = - when (index) { - 0 -> groupId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - fun toBuilder() = Builder().from(this) companion object { @@ -50,7 +39,6 @@ private constructor( } /** A builder for [GroupRetrieveParams]. */ - @NoAutoDetect class Builder internal constructor() { private var groupId: String? = null @@ -185,6 +173,16 @@ private constructor( ) } + fun _pathParam(index: Int): String = + when (index) { + 0 -> groupId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupUpdateParams.kt index f75704bb..5e1672d5 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupUpdateParams.kt @@ -6,19 +6,18 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -137,179 +136,499 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body + fun toBuilder() = Builder().from(this) - fun _pathParam(index: Int): String = - when (index) { - 0 -> groupId - else -> "" + companion object { + + /** + * Returns a mutable builder for constructing an instance of [GroupUpdateParams]. + * + * The following fields are required: + * ```java + * .groupId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [GroupUpdateParams]. */ + class Builder internal constructor() { + + private var groupId: String? = null + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(groupUpdateParams: GroupUpdateParams) = apply { + groupId = groupUpdateParams.groupId + body = groupUpdateParams.body.toBuilder() + additionalHeaders = groupUpdateParams.additionalHeaders.toBuilder() + additionalQueryParams = groupUpdateParams.additionalQueryParams.toBuilder() } - override fun _headers(): Headers = additionalHeaders + /** Group id */ + fun groupId(groupId: String) = apply { this.groupId = groupId } - override fun _queryParams(): QueryParams = additionalQueryParams + /** A list of group IDs to add to the group's inheriting-from set */ + fun addMemberGroups(addMemberGroups: List?) = apply { + body.addMemberGroups(addMemberGroups) + } - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("add_member_groups") - @ExcludeMissing - private val addMemberGroups: JsonField> = JsonMissing.of(), - @JsonProperty("add_member_users") - @ExcludeMissing - private val addMemberUsers: JsonField> = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("remove_member_groups") - @ExcludeMissing - private val removeMemberGroups: JsonField> = JsonMissing.of(), - @JsonProperty("remove_member_users") - @ExcludeMissing - private val removeMemberUsers: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + /** Alias for calling [Builder.addMemberGroups] with `addMemberGroups.orElse(null)`. */ + fun addMemberGroups(addMemberGroups: Optional>) = + addMemberGroups(addMemberGroups.getOrNull()) /** - * A list of group IDs to add to the group's inheriting-from set + * Sets [Builder.addMemberGroups] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.addMemberGroups] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun addMemberGroups(): Optional> = - Optional.ofNullable(addMemberGroups.getNullable("add_member_groups")) + fun addMemberGroups(addMemberGroups: JsonField>) = apply { + body.addMemberGroups(addMemberGroups) + } /** - * A list of user IDs to add to the group + * Adds a single [String] to [addMemberGroups]. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addMemberUsers(): Optional> = - Optional.ofNullable(addMemberUsers.getNullable("add_member_users")) + fun addAddMemberGroup(addMemberGroup: String) = apply { + body.addAddMemberGroup(addMemberGroup) + } - /** - * Textual description of the group - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + /** A list of user IDs to add to the group */ + fun addMemberUsers(addMemberUsers: List?) = apply { + body.addMemberUsers(addMemberUsers) + } + + /** Alias for calling [Builder.addMemberUsers] with `addMemberUsers.orElse(null)`. */ + fun addMemberUsers(addMemberUsers: Optional>) = + addMemberUsers(addMemberUsers.getOrNull()) /** - * Name of the group + * Sets [Builder.addMemberUsers] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.addMemberUsers] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun addMemberUsers(addMemberUsers: JsonField>) = apply { + body.addMemberUsers(addMemberUsers) + } /** - * A list of group IDs to remove from the group's inheriting-from set + * Adds a single [String] to [addMemberUsers]. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * @throws IllegalStateException if the field was previously set to a non-list. */ - fun removeMemberGroups(): Optional> = - Optional.ofNullable(removeMemberGroups.getNullable("remove_member_groups")) + fun addAddMemberUser(addMemberUser: String) = apply { body.addAddMemberUser(addMemberUser) } + + /** Textual description of the group */ + fun description(description: String?) = apply { body.description(description) } + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) /** - * A list of user IDs to remove from the group + * Sets [Builder.description] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun removeMemberUsers(): Optional> = - Optional.ofNullable(removeMemberUsers.getNullable("remove_member_users")) + fun description(description: JsonField) = apply { body.description(description) } + + /** Name of the group */ + fun name(name: String?) = apply { body.name(name) } + + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) /** - * Returns the raw JSON value of [addMemberGroups]. + * Sets [Builder.name] to an arbitrary JSON value. * - * Unlike [addMemberGroups], this method doesn't throw if the JSON field has an unexpected - * type. + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("add_member_groups") - @ExcludeMissing - fun _addMemberGroups(): JsonField> = addMemberGroups + fun name(name: JsonField) = apply { body.name(name) } + + /** A list of group IDs to remove from the group's inheriting-from set */ + fun removeMemberGroups(removeMemberGroups: List?) = apply { + body.removeMemberGroups(removeMemberGroups) + } /** - * Returns the raw JSON value of [addMemberUsers]. - * - * Unlike [addMemberUsers], this method doesn't throw if the JSON field has an unexpected - * type. + * Alias for calling [Builder.removeMemberGroups] with `removeMemberGroups.orElse(null)`. */ - @JsonProperty("add_member_users") - @ExcludeMissing - fun _addMemberUsers(): JsonField> = addMemberUsers + fun removeMemberGroups(removeMemberGroups: Optional>) = + removeMemberGroups(removeMemberGroups.getOrNull()) /** - * Returns the raw JSON value of [description]. + * Sets [Builder.removeMemberGroups] to an arbitrary JSON value. * - * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.removeMemberGroups] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. */ - @JsonProperty("description") - @ExcludeMissing - fun _description(): JsonField = description + fun removeMemberGroups(removeMemberGroups: JsonField>) = apply { + body.removeMemberGroups(removeMemberGroups) + } /** - * Returns the raw JSON value of [name]. + * Adds a single [String] to [removeMemberGroups]. * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + * @throws IllegalStateException if the field was previously set to a non-list. */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + fun addRemoveMemberGroup(removeMemberGroup: String) = apply { + body.addRemoveMemberGroup(removeMemberGroup) + } + + /** A list of user IDs to remove from the group */ + fun removeMemberUsers(removeMemberUsers: List?) = apply { + body.removeMemberUsers(removeMemberUsers) + } + + /** Alias for calling [Builder.removeMemberUsers] with `removeMemberUsers.orElse(null)`. */ + fun removeMemberUsers(removeMemberUsers: Optional>) = + removeMemberUsers(removeMemberUsers.getOrNull()) /** - * Returns the raw JSON value of [removeMemberGroups]. + * Sets [Builder.removeMemberUsers] to an arbitrary JSON value. * - * Unlike [removeMemberGroups], this method doesn't throw if the JSON field has an - * unexpected type. + * You should usually call [Builder.removeMemberUsers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. */ - @JsonProperty("remove_member_groups") - @ExcludeMissing - fun _removeMemberGroups(): JsonField> = removeMemberGroups + fun removeMemberUsers(removeMemberUsers: JsonField>) = apply { + body.removeMemberUsers(removeMemberUsers) + } /** - * Returns the raw JSON value of [removeMemberUsers]. + * Adds a single [String] to [removeMemberUsers]. * - * Unlike [removeMemberUsers], this method doesn't throw if the JSON field has an unexpected - * type. + * @throws IllegalStateException if the field was previously set to a non-list. */ - @JsonProperty("remove_member_users") - @ExcludeMissing - fun _removeMemberUsers(): JsonField> = removeMemberUsers + fun addRemoveMemberUser(removeMemberUser: String) = apply { + body.addRemoveMemberUser(removeMemberUser) + } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } - private var validated: Boolean = false + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } - fun validate(): Body = apply { - if (validated) { - return@apply + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) } - addMemberGroups() - addMemberUsers() - description() - name() - removeMemberGroups() - removeMemberUsers() - validated = true + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) } - fun toBuilder() = Builder().from(this) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - companion object { + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** Returns a mutable builder for constructing an instance of [Body]. */ - @JvmStatic fun builder() = Builder() + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(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 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) + } + + /** + * Returns an immutable instance of [GroupUpdateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .groupId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupUpdateParams = + GroupUpdateParams( + checkRequired("groupId", groupId), + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + @JvmSynthetic internal fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> groupId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val addMemberGroups: JsonField>, + private val addMemberUsers: JsonField>, + private val description: JsonField, + private val name: JsonField, + private val removeMemberGroups: JsonField>, + private val removeMemberUsers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("add_member_groups") + @ExcludeMissing + addMemberGroups: JsonField> = JsonMissing.of(), + @JsonProperty("add_member_users") + @ExcludeMissing + addMemberUsers: JsonField> = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("remove_member_groups") + @ExcludeMissing + removeMemberGroups: JsonField> = JsonMissing.of(), + @JsonProperty("remove_member_users") + @ExcludeMissing + removeMemberUsers: JsonField> = JsonMissing.of(), + ) : this( + addMemberGroups, + addMemberUsers, + description, + name, + removeMemberGroups, + removeMemberUsers, + mutableMapOf(), + ) + + /** + * A list of group IDs to add to the group's inheriting-from set + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun addMemberGroups(): Optional> = + Optional.ofNullable(addMemberGroups.getNullable("add_member_groups")) + + /** + * A list of user IDs to add to the group + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun addMemberUsers(): Optional> = + Optional.ofNullable(addMemberUsers.getNullable("add_member_users")) + + /** + * Textual description of the group + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun description(): Optional = + Optional.ofNullable(description.getNullable("description")) + + /** + * Name of the group + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + /** + * A list of group IDs to remove from the group's inheriting-from set + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun removeMemberGroups(): Optional> = + Optional.ofNullable(removeMemberGroups.getNullable("remove_member_groups")) + + /** + * A list of user IDs to remove from the group + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun removeMemberUsers(): Optional> = + Optional.ofNullable(removeMemberUsers.getNullable("remove_member_users")) + + /** + * Returns the raw JSON value of [addMemberGroups]. + * + * Unlike [addMemberGroups], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("add_member_groups") + @ExcludeMissing + fun _addMemberGroups(): JsonField> = addMemberGroups + + /** + * Returns the raw JSON value of [addMemberUsers]. + * + * Unlike [addMemberUsers], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("add_member_users") + @ExcludeMissing + fun _addMemberUsers(): JsonField> = addMemberUsers + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [removeMemberGroups]. + * + * Unlike [removeMemberGroups], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("remove_member_groups") + @ExcludeMissing + fun _removeMemberGroups(): JsonField> = removeMemberGroups + + /** + * Returns the raw JSON value of [removeMemberUsers]. + * + * Unlike [removeMemberUsers], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("remove_member_users") + @ExcludeMissing + fun _removeMemberUsers(): JsonField> = removeMemberUsers + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Body]. */ + @JvmStatic fun builder() = Builder() } /** A builder for [Body]. */ @@ -527,344 +846,42 @@ private constructor( name, (removeMemberGroups ?: JsonMissing.of()).map { it.toImmutable() }, (removeMemberUsers ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + private var validated: Boolean = false - return /* spotless:off */ other is Body && addMemberGroups == other.addMemberGroups && addMemberUsers == other.addMemberUsers && description == other.description && name == other.name && removeMemberGroups == other.removeMemberGroups && removeMemberUsers == other.removeMemberUsers && additionalProperties == other.additionalProperties /* spotless:on */ - } + fun validate(): Body = apply { + if (validated) { + return@apply + } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(addMemberGroups, addMemberUsers, description, name, removeMemberGroups, removeMemberUsers, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Body{addMemberGroups=$addMemberGroups, addMemberUsers=$addMemberUsers, description=$description, name=$name, removeMemberGroups=$removeMemberGroups, removeMemberUsers=$removeMemberUsers, additionalProperties=$additionalProperties}" - } - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [GroupUpdateParams]. - * - * The following fields are required: - * ```java - * .groupId() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [GroupUpdateParams]. */ - @NoAutoDetect - class Builder internal constructor() { - - private var groupId: String? = null - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - - @JvmSynthetic - internal fun from(groupUpdateParams: GroupUpdateParams) = apply { - groupId = groupUpdateParams.groupId - body = groupUpdateParams.body.toBuilder() - additionalHeaders = groupUpdateParams.additionalHeaders.toBuilder() - additionalQueryParams = groupUpdateParams.additionalQueryParams.toBuilder() - } - - /** Group id */ - fun groupId(groupId: String) = apply { this.groupId = groupId } - - /** A list of group IDs to add to the group's inheriting-from set */ - fun addMemberGroups(addMemberGroups: List?) = apply { - body.addMemberGroups(addMemberGroups) - } - - /** Alias for calling [Builder.addMemberGroups] with `addMemberGroups.orElse(null)`. */ - fun addMemberGroups(addMemberGroups: Optional>) = - addMemberGroups(addMemberGroups.getOrNull()) - - /** - * Sets [Builder.addMemberGroups] to an arbitrary JSON value. - * - * You should usually call [Builder.addMemberGroups] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun addMemberGroups(addMemberGroups: JsonField>) = apply { - body.addMemberGroups(addMemberGroups) - } - - /** - * Adds a single [String] to [addMemberGroups]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addAddMemberGroup(addMemberGroup: String) = apply { - body.addAddMemberGroup(addMemberGroup) - } - - /** A list of user IDs to add to the group */ - fun addMemberUsers(addMemberUsers: List?) = apply { - body.addMemberUsers(addMemberUsers) - } - - /** Alias for calling [Builder.addMemberUsers] with `addMemberUsers.orElse(null)`. */ - fun addMemberUsers(addMemberUsers: Optional>) = - addMemberUsers(addMemberUsers.getOrNull()) - - /** - * Sets [Builder.addMemberUsers] to an arbitrary JSON value. - * - * You should usually call [Builder.addMemberUsers] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun addMemberUsers(addMemberUsers: JsonField>) = apply { - body.addMemberUsers(addMemberUsers) - } - - /** - * Adds a single [String] to [addMemberUsers]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addAddMemberUser(addMemberUser: String) = apply { body.addAddMemberUser(addMemberUser) } - - /** Textual description of the group */ - fun description(description: String?) = apply { body.description(description) } - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) - - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun description(description: JsonField) = apply { body.description(description) } - - /** Name of the group */ - fun name(name: String?) = apply { body.name(name) } - - /** Alias for calling [Builder.name] with `name.orElse(null)`. */ - fun name(name: Optional) = name(name.getOrNull()) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun name(name: JsonField) = apply { body.name(name) } - - /** A list of group IDs to remove from the group's inheriting-from set */ - fun removeMemberGroups(removeMemberGroups: List?) = apply { - body.removeMemberGroups(removeMemberGroups) - } - - /** - * Alias for calling [Builder.removeMemberGroups] with `removeMemberGroups.orElse(null)`. - */ - fun removeMemberGroups(removeMemberGroups: Optional>) = - removeMemberGroups(removeMemberGroups.getOrNull()) - - /** - * Sets [Builder.removeMemberGroups] to an arbitrary JSON value. - * - * You should usually call [Builder.removeMemberGroups] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun removeMemberGroups(removeMemberGroups: JsonField>) = apply { - body.removeMemberGroups(removeMemberGroups) - } - - /** - * Adds a single [String] to [removeMemberGroups]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addRemoveMemberGroup(removeMemberGroup: String) = apply { - body.addRemoveMemberGroup(removeMemberGroup) - } - - /** A list of user IDs to remove from the group */ - fun removeMemberUsers(removeMemberUsers: List?) = apply { - body.removeMemberUsers(removeMemberUsers) - } - - /** Alias for calling [Builder.removeMemberUsers] with `removeMemberUsers.orElse(null)`. */ - fun removeMemberUsers(removeMemberUsers: Optional>) = - removeMemberUsers(removeMemberUsers.getOrNull()) - - /** - * Sets [Builder.removeMemberUsers] to an arbitrary JSON value. - * - * You should usually call [Builder.removeMemberUsers] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun removeMemberUsers(removeMemberUsers: JsonField>) = apply { - body.removeMemberUsers(removeMemberUsers) - } - - /** - * Adds a single [String] to [removeMemberUsers]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addRemoveMemberUser(removeMemberUser: String) = apply { - body.addRemoveMemberUser(removeMemberUser) - } - - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) - } - - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } - - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) - } - - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } - - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } - - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } - - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(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 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) + addMemberGroups() + addMemberUsers() + description() + name() + removeMemberGroups() + removeMemberUsers() + validated = true } - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - 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) + return /* spotless:off */ other is Body && addMemberGroups == other.addMemberGroups && addMemberUsers == other.addMemberUsers && description == other.description && name == other.name && removeMemberGroups == other.removeMemberGroups && removeMemberUsers == other.removeMemberUsers && additionalProperties == other.additionalProperties /* spotless:on */ } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) - } - - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(addMemberGroups, addMemberUsers, description, name, removeMemberGroups, removeMemberUsers, additionalProperties) } + /* spotless:on */ - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) - } + override fun hashCode(): Int = hashCode - /** - * Returns an immutable instance of [GroupUpdateParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .groupId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): GroupUpdateParams = - GroupUpdateParams( - checkRequired("groupId", groupId), - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + override fun toString() = + "Body{addMemberGroups=$addMemberGroups, addMemberUsers=$addMemberUsers, description=$description, name=$name, removeMemberGroups=$removeMemberGroups, removeMemberUsers=$removeMemberUsers, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertDatasetEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertDatasetEvent.kt index abeb2f43..5c9c0ead 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertDatasetEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertDatasetEvent.kt @@ -6,9 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkKnown -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter @@ -16,54 +14,77 @@ import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull /** A dataset event */ -@NoAutoDetect class InsertDatasetEvent -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("_is_merge") - @ExcludeMissing - private val _isMerge: JsonField = JsonMissing.of(), - @JsonProperty("_merge_paths") - @ExcludeMissing - private val _mergePaths: JsonField>> = JsonMissing.of(), - @JsonProperty("_object_delete") - @ExcludeMissing - private val _objectDelete: JsonField = JsonMissing.of(), - @JsonProperty("_parent_id") - @ExcludeMissing - private val _parentId: JsonField = JsonMissing.of(), - @JsonProperty("created") - @ExcludeMissing - private val created: JsonField = JsonMissing.of(), - @JsonProperty("expected") @ExcludeMissing private val expected: JsonValue = JsonMissing.of(), - @JsonProperty("input") @ExcludeMissing private val input: JsonValue = JsonMissing.of(), - @JsonProperty("metadata") - @ExcludeMissing - private val metadata: JsonField = JsonMissing.of(), - @JsonProperty("origin") - @ExcludeMissing - private val origin: JsonField = JsonMissing.of(), - @JsonProperty("root_span_id") - @ExcludeMissing - private val rootSpanId: JsonField = JsonMissing.of(), - @JsonProperty("span_id") - @ExcludeMissing - private val spanId: JsonField = JsonMissing.of(), - @JsonProperty("span_parents") - @ExcludeMissing - private val spanParents: JsonField> = JsonMissing.of(), - @JsonProperty("tags") - @ExcludeMissing - private val tags: JsonField> = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val _isMerge: JsonField, + private val _mergePaths: JsonField>>, + private val _objectDelete: JsonField, + private val _parentId: JsonField, + private val created: JsonField, + private val expected: JsonValue, + private val input: JsonValue, + private val metadata: JsonField, + private val origin: JsonField, + private val rootSpanId: JsonField, + private val spanId: JsonField, + private val spanParents: JsonField>, + private val tags: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("_is_merge") @ExcludeMissing _isMerge: JsonField = JsonMissing.of(), + @JsonProperty("_merge_paths") + @ExcludeMissing + _mergePaths: JsonField>> = JsonMissing.of(), + @JsonProperty("_object_delete") + @ExcludeMissing + _objectDelete: JsonField = JsonMissing.of(), + @JsonProperty("_parent_id") @ExcludeMissing _parentId: JsonField = JsonMissing.of(), + @JsonProperty("created") + @ExcludeMissing + created: JsonField = JsonMissing.of(), + @JsonProperty("expected") @ExcludeMissing expected: JsonValue = JsonMissing.of(), + @JsonProperty("input") @ExcludeMissing input: JsonValue = JsonMissing.of(), + @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("origin") + @ExcludeMissing + origin: JsonField = JsonMissing.of(), + @JsonProperty("root_span_id") + @ExcludeMissing + rootSpanId: JsonField = JsonMissing.of(), + @JsonProperty("span_id") @ExcludeMissing spanId: JsonField = JsonMissing.of(), + @JsonProperty("span_parents") + @ExcludeMissing + spanParents: JsonField> = JsonMissing.of(), + @JsonProperty("tags") @ExcludeMissing tags: JsonField> = JsonMissing.of(), + ) : this( + id, + _isMerge, + _mergePaths, + _objectDelete, + _parentId, + created, + expected, + input, + metadata, + origin, + rootSpanId, + spanId, + spanParents, + tags, + mutableMapOf(), + ) + /** * A unique identifier for the dataset event. If you don't provide one, BrainTrust will generate * one for you @@ -341,31 +362,15 @@ private constructor( */ @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): InsertDatasetEvent = apply { - if (validated) { - return@apply - } - - id() - _isMerge() - _mergePaths() - _objectDelete() - _parentId() - created() - metadata().ifPresent { it.validate() } - origin().ifPresent { it.validate() } - rootSpanId() - spanId() - spanParents() - tags() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -801,10 +806,32 @@ private constructor( spanId, (spanParents ?: JsonMissing.of()).map { it.toImmutable() }, (tags ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): InsertDatasetEvent = apply { + if (validated) { + return@apply + } + + id() + _isMerge() + _mergePaths() + _objectDelete() + _parentId() + created() + metadata().ifPresent { it.validate() } + origin().ifPresent { it.validate() } + rootSpanId() + spanId() + spanParents() + tags() + validated = true + } + /** * A dictionary with additional data about the test example, model outputs, or just about * anything else that's relevant, that you can use to help find and analyze examples later. For @@ -812,17 +839,17 @@ private constructor( * slice/dice later. The values in `metadata` can be any JSON-serializable type, but its keys * must be strings */ - @NoAutoDetect class Metadata - @JsonCreator private constructor( - @JsonProperty("model") - @ExcludeMissing - private val model: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val model: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("model") @ExcludeMissing model: JsonField = JsonMissing.of() + ) : this(model, mutableMapOf()) + /** * The model used for this example * @@ -838,20 +865,15 @@ private constructor( */ @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - model() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -912,7 +934,18 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(model, additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(model, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + model() + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertEventsResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertEventsResponse.kt index 8d756030..fb891b77 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertEventsResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertEventsResponse.kt @@ -6,28 +6,28 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects -@NoAutoDetect class InsertEventsResponse -@JsonCreator private constructor( - @JsonProperty("row_ids") - @ExcludeMissing - private val rowIds: JsonField> = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val rowIds: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("row_ids") @ExcludeMissing rowIds: JsonField> = JsonMissing.of() + ) : this(rowIds, mutableMapOf()) + /** * The ids of all rows that were inserted, aligning one-to-one with the rows provided as input * @@ -43,20 +43,15 @@ private constructor( */ @JsonProperty("row_ids") @ExcludeMissing fun _rowIds(): JsonField> = rowIds + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): InsertEventsResponse = apply { - if (validated) { - return@apply - } - - rowIds() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -148,10 +143,21 @@ private constructor( fun build(): InsertEventsResponse = InsertEventsResponse( checkRequired("rowIds", rowIds).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): InsertEventsResponse = apply { + if (validated) { + return@apply + } + + rowIds() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertExperimentEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertExperimentEvent.kt index 946c2f68..d4cc1375 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertExperimentEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertExperimentEvent.kt @@ -6,9 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkKnown -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter @@ -16,68 +14,97 @@ import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull /** An experiment event */ -@NoAutoDetect class InsertExperimentEvent -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("_is_merge") - @ExcludeMissing - private val _isMerge: JsonField = JsonMissing.of(), - @JsonProperty("_merge_paths") - @ExcludeMissing - private val _mergePaths: JsonField>> = JsonMissing.of(), - @JsonProperty("_object_delete") - @ExcludeMissing - private val _objectDelete: JsonField = JsonMissing.of(), - @JsonProperty("_parent_id") - @ExcludeMissing - private val _parentId: JsonField = JsonMissing.of(), - @JsonProperty("context") - @ExcludeMissing - private val context: JsonField = JsonMissing.of(), - @JsonProperty("created") - @ExcludeMissing - private val created: JsonField = JsonMissing.of(), - @JsonProperty("error") @ExcludeMissing private val error: JsonValue = JsonMissing.of(), - @JsonProperty("expected") @ExcludeMissing private val expected: JsonValue = JsonMissing.of(), - @JsonProperty("input") @ExcludeMissing private val input: JsonValue = JsonMissing.of(), - @JsonProperty("metadata") - @ExcludeMissing - private val metadata: JsonField = JsonMissing.of(), - @JsonProperty("metrics") - @ExcludeMissing - private val metrics: JsonField = JsonMissing.of(), - @JsonProperty("origin") - @ExcludeMissing - private val origin: JsonField = JsonMissing.of(), - @JsonProperty("output") @ExcludeMissing private val output: JsonValue = JsonMissing.of(), - @JsonProperty("root_span_id") - @ExcludeMissing - private val rootSpanId: JsonField = JsonMissing.of(), - @JsonProperty("scores") - @ExcludeMissing - private val scores: JsonField = JsonMissing.of(), - @JsonProperty("span_attributes") - @ExcludeMissing - private val spanAttributes: JsonField = JsonMissing.of(), - @JsonProperty("span_id") - @ExcludeMissing - private val spanId: JsonField = JsonMissing.of(), - @JsonProperty("span_parents") - @ExcludeMissing - private val spanParents: JsonField> = JsonMissing.of(), - @JsonProperty("tags") - @ExcludeMissing - private val tags: JsonField> = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val _isMerge: JsonField, + private val _mergePaths: JsonField>>, + private val _objectDelete: JsonField, + private val _parentId: JsonField, + private val context: JsonField, + private val created: JsonField, + private val error: JsonValue, + private val expected: JsonValue, + private val input: JsonValue, + private val metadata: JsonField, + private val metrics: JsonField, + private val origin: JsonField, + private val output: JsonValue, + private val rootSpanId: JsonField, + private val scores: JsonField, + private val spanAttributes: JsonField, + private val spanId: JsonField, + private val spanParents: JsonField>, + private val tags: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("_is_merge") @ExcludeMissing _isMerge: JsonField = JsonMissing.of(), + @JsonProperty("_merge_paths") + @ExcludeMissing + _mergePaths: JsonField>> = JsonMissing.of(), + @JsonProperty("_object_delete") + @ExcludeMissing + _objectDelete: JsonField = JsonMissing.of(), + @JsonProperty("_parent_id") @ExcludeMissing _parentId: JsonField = JsonMissing.of(), + @JsonProperty("context") @ExcludeMissing context: JsonField = JsonMissing.of(), + @JsonProperty("created") + @ExcludeMissing + created: JsonField = JsonMissing.of(), + @JsonProperty("error") @ExcludeMissing error: JsonValue = JsonMissing.of(), + @JsonProperty("expected") @ExcludeMissing expected: JsonValue = JsonMissing.of(), + @JsonProperty("input") @ExcludeMissing input: JsonValue = JsonMissing.of(), + @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("metrics") @ExcludeMissing metrics: JsonField = JsonMissing.of(), + @JsonProperty("origin") + @ExcludeMissing + origin: JsonField = JsonMissing.of(), + @JsonProperty("output") @ExcludeMissing output: JsonValue = JsonMissing.of(), + @JsonProperty("root_span_id") + @ExcludeMissing + rootSpanId: JsonField = JsonMissing.of(), + @JsonProperty("scores") @ExcludeMissing scores: JsonField = JsonMissing.of(), + @JsonProperty("span_attributes") + @ExcludeMissing + spanAttributes: JsonField = JsonMissing.of(), + @JsonProperty("span_id") @ExcludeMissing spanId: JsonField = JsonMissing.of(), + @JsonProperty("span_parents") + @ExcludeMissing + spanParents: JsonField> = JsonMissing.of(), + @JsonProperty("tags") @ExcludeMissing tags: JsonField> = JsonMissing.of(), + ) : this( + id, + _isMerge, + _mergePaths, + _objectDelete, + _parentId, + context, + created, + error, + expected, + input, + metadata, + metrics, + origin, + output, + rootSpanId, + scores, + spanAttributes, + spanId, + spanParents, + tags, + mutableMapOf(), + ) + /** * A unique identifier for the experiment event. If you don't provide one, BrainTrust will * generate one for you @@ -449,35 +476,15 @@ private constructor( */ @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): InsertExperimentEvent = apply { - if (validated) { - return@apply - } - - id() - _isMerge() - _mergePaths() - _objectDelete() - _parentId() - context().ifPresent { it.validate() } - created() - metadata().ifPresent { it.validate() } - metrics().ifPresent { it.validate() } - origin().ifPresent { it.validate() } - rootSpanId() - scores().ifPresent { it.validate() } - spanAttributes().ifPresent { it.validate() } - spanId() - spanParents() - tags() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1027,32 +1034,62 @@ private constructor( spanId, (spanParents ?: JsonMissing.of()).map { it.toImmutable() }, (tags ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): InsertExperimentEvent = apply { + if (validated) { + return@apply + } + + id() + _isMerge() + _mergePaths() + _objectDelete() + _parentId() + context().ifPresent { it.validate() } + created() + metadata().ifPresent { it.validate() } + metrics().ifPresent { it.validate() } + origin().ifPresent { it.validate() } + rootSpanId() + scores().ifPresent { it.validate() } + spanAttributes().ifPresent { it.validate() } + spanId() + spanParents() + tags() + validated = true + } + /** * Context is additional information about the code that produced the experiment event. It is * essentially the textual counterpart to `metrics`. Use the `caller_*` attributes to track the * location in code which produced the experiment event */ - @NoAutoDetect class Context - @JsonCreator private constructor( - @JsonProperty("caller_filename") - @ExcludeMissing - private val callerFilename: JsonField = JsonMissing.of(), - @JsonProperty("caller_functionname") - @ExcludeMissing - private val callerFunctionname: JsonField = JsonMissing.of(), - @JsonProperty("caller_lineno") - @ExcludeMissing - private val callerLineno: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val callerFilename: JsonField, + private val callerFunctionname: JsonField, + private val callerLineno: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("caller_filename") + @ExcludeMissing + callerFilename: JsonField = JsonMissing.of(), + @JsonProperty("caller_functionname") + @ExcludeMissing + callerFunctionname: JsonField = JsonMissing.of(), + @JsonProperty("caller_lineno") + @ExcludeMissing + callerLineno: JsonField = JsonMissing.of(), + ) : this(callerFilename, callerFunctionname, callerLineno, mutableMapOf()) + /** * Name of the file in code where the experiment event was created * @@ -1110,22 +1147,15 @@ private constructor( @ExcludeMissing fun _callerLineno(): JsonField = callerLineno + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Context = apply { - if (validated) { - return@apply - } - - callerFilename() - callerFunctionname() - callerLineno() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1245,10 +1275,23 @@ private constructor( callerFilename, callerFunctionname, callerLineno, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Context = apply { + if (validated) { + return@apply + } + + callerFilename() + callerFunctionname() + callerLineno() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1274,17 +1317,17 @@ private constructor( * slice/dice later. The values in `metadata` can be any JSON-serializable type, but its keys * must be strings */ - @NoAutoDetect class Metadata - @JsonCreator private constructor( - @JsonProperty("model") - @ExcludeMissing - private val model: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val model: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("model") @ExcludeMissing model: JsonField = JsonMissing.of() + ) : this(model, mutableMapOf()) + /** * The model used for this example * @@ -1300,20 +1343,15 @@ private constructor( */ @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - model() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1374,7 +1412,18 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(model, additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(model, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + model() + validated = true } override fun equals(other: Any?): Boolean { @@ -1400,36 +1449,51 @@ private constructor( * experiment event. Use "start" and "end" to track the time span over which the experiment * event was produced */ - @NoAutoDetect class Metrics - @JsonCreator private constructor( - @JsonProperty("caller_filename") - @ExcludeMissing - private val callerFilename: JsonValue = JsonMissing.of(), - @JsonProperty("caller_functionname") - @ExcludeMissing - private val callerFunctionname: JsonValue = JsonMissing.of(), - @JsonProperty("caller_lineno") - @ExcludeMissing - private val callerLineno: JsonValue = JsonMissing.of(), - @JsonProperty("completion_tokens") - @ExcludeMissing - private val completionTokens: JsonField = JsonMissing.of(), - @JsonProperty("end") @ExcludeMissing private val end: JsonField = JsonMissing.of(), - @JsonProperty("prompt_tokens") - @ExcludeMissing - private val promptTokens: JsonField = JsonMissing.of(), - @JsonProperty("start") - @ExcludeMissing - private val start: JsonField = JsonMissing.of(), - @JsonProperty("tokens") - @ExcludeMissing - private val tokens: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val callerFilename: JsonValue, + private val callerFunctionname: JsonValue, + private val callerLineno: JsonValue, + private val completionTokens: JsonField, + private val end: JsonField, + private val promptTokens: JsonField, + private val start: JsonField, + private val tokens: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("caller_filename") + @ExcludeMissing + callerFilename: JsonValue = JsonMissing.of(), + @JsonProperty("caller_functionname") + @ExcludeMissing + callerFunctionname: JsonValue = JsonMissing.of(), + @JsonProperty("caller_lineno") + @ExcludeMissing + callerLineno: JsonValue = JsonMissing.of(), + @JsonProperty("completion_tokens") + @ExcludeMissing + completionTokens: JsonField = JsonMissing.of(), + @JsonProperty("end") @ExcludeMissing end: JsonField = JsonMissing.of(), + @JsonProperty("prompt_tokens") + @ExcludeMissing + promptTokens: JsonField = JsonMissing.of(), + @JsonProperty("start") @ExcludeMissing start: JsonField = JsonMissing.of(), + @JsonProperty("tokens") @ExcludeMissing tokens: JsonField = JsonMissing.of(), + ) : this( + callerFilename, + callerFunctionname, + callerLineno, + completionTokens, + end, + promptTokens, + start, + tokens, + mutableMapOf(), + ) + /** This metric is deprecated */ @JsonProperty("caller_filename") @ExcludeMissing @@ -1530,24 +1594,15 @@ private constructor( */ @JsonProperty("tokens") @ExcludeMissing fun _tokens(): JsonField = tokens + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Metrics = apply { - if (validated) { - return@apply - } - - completionTokens() - end() - promptTokens() - start() - tokens() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1761,10 +1816,25 @@ private constructor( promptTokens, start, tokens, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Metrics = apply { + if (validated) { + return@apply + } + + completionTokens() + end() + promptTokens() + start() + tokens() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1792,27 +1862,20 @@ private constructor( * whether the summarization was covering similar concepts or not. You can use these scores to * help you sort, filter, and compare experiments */ - @NoAutoDetect class Scores - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Scores = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1856,7 +1919,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Scores = Scores(additionalProperties.toImmutable()) + fun build(): Scores = Scores(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Scores = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertProjectLogsEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertProjectLogsEvent.kt index af3e8ffb..1c4d1702 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertProjectLogsEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertProjectLogsEvent.kt @@ -6,9 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkKnown -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter @@ -16,68 +14,97 @@ import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull /** A project logs event */ -@NoAutoDetect class InsertProjectLogsEvent -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("_is_merge") - @ExcludeMissing - private val _isMerge: JsonField = JsonMissing.of(), - @JsonProperty("_merge_paths") - @ExcludeMissing - private val _mergePaths: JsonField>> = JsonMissing.of(), - @JsonProperty("_object_delete") - @ExcludeMissing - private val _objectDelete: JsonField = JsonMissing.of(), - @JsonProperty("_parent_id") - @ExcludeMissing - private val _parentId: JsonField = JsonMissing.of(), - @JsonProperty("context") - @ExcludeMissing - private val context: JsonField = JsonMissing.of(), - @JsonProperty("created") - @ExcludeMissing - private val created: JsonField = JsonMissing.of(), - @JsonProperty("error") @ExcludeMissing private val error: JsonValue = JsonMissing.of(), - @JsonProperty("expected") @ExcludeMissing private val expected: JsonValue = JsonMissing.of(), - @JsonProperty("input") @ExcludeMissing private val input: JsonValue = JsonMissing.of(), - @JsonProperty("metadata") - @ExcludeMissing - private val metadata: JsonField = JsonMissing.of(), - @JsonProperty("metrics") - @ExcludeMissing - private val metrics: JsonField = JsonMissing.of(), - @JsonProperty("origin") - @ExcludeMissing - private val origin: JsonField = JsonMissing.of(), - @JsonProperty("output") @ExcludeMissing private val output: JsonValue = JsonMissing.of(), - @JsonProperty("root_span_id") - @ExcludeMissing - private val rootSpanId: JsonField = JsonMissing.of(), - @JsonProperty("scores") - @ExcludeMissing - private val scores: JsonField = JsonMissing.of(), - @JsonProperty("span_attributes") - @ExcludeMissing - private val spanAttributes: JsonField = JsonMissing.of(), - @JsonProperty("span_id") - @ExcludeMissing - private val spanId: JsonField = JsonMissing.of(), - @JsonProperty("span_parents") - @ExcludeMissing - private val spanParents: JsonField> = JsonMissing.of(), - @JsonProperty("tags") - @ExcludeMissing - private val tags: JsonField> = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val _isMerge: JsonField, + private val _mergePaths: JsonField>>, + private val _objectDelete: JsonField, + private val _parentId: JsonField, + private val context: JsonField, + private val created: JsonField, + private val error: JsonValue, + private val expected: JsonValue, + private val input: JsonValue, + private val metadata: JsonField, + private val metrics: JsonField, + private val origin: JsonField, + private val output: JsonValue, + private val rootSpanId: JsonField, + private val scores: JsonField, + private val spanAttributes: JsonField, + private val spanId: JsonField, + private val spanParents: JsonField>, + private val tags: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("_is_merge") @ExcludeMissing _isMerge: JsonField = JsonMissing.of(), + @JsonProperty("_merge_paths") + @ExcludeMissing + _mergePaths: JsonField>> = JsonMissing.of(), + @JsonProperty("_object_delete") + @ExcludeMissing + _objectDelete: JsonField = JsonMissing.of(), + @JsonProperty("_parent_id") @ExcludeMissing _parentId: JsonField = JsonMissing.of(), + @JsonProperty("context") @ExcludeMissing context: JsonField = JsonMissing.of(), + @JsonProperty("created") + @ExcludeMissing + created: JsonField = JsonMissing.of(), + @JsonProperty("error") @ExcludeMissing error: JsonValue = JsonMissing.of(), + @JsonProperty("expected") @ExcludeMissing expected: JsonValue = JsonMissing.of(), + @JsonProperty("input") @ExcludeMissing input: JsonValue = JsonMissing.of(), + @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("metrics") @ExcludeMissing metrics: JsonField = JsonMissing.of(), + @JsonProperty("origin") + @ExcludeMissing + origin: JsonField = JsonMissing.of(), + @JsonProperty("output") @ExcludeMissing output: JsonValue = JsonMissing.of(), + @JsonProperty("root_span_id") + @ExcludeMissing + rootSpanId: JsonField = JsonMissing.of(), + @JsonProperty("scores") @ExcludeMissing scores: JsonField = JsonMissing.of(), + @JsonProperty("span_attributes") + @ExcludeMissing + spanAttributes: JsonField = JsonMissing.of(), + @JsonProperty("span_id") @ExcludeMissing spanId: JsonField = JsonMissing.of(), + @JsonProperty("span_parents") + @ExcludeMissing + spanParents: JsonField> = JsonMissing.of(), + @JsonProperty("tags") @ExcludeMissing tags: JsonField> = JsonMissing.of(), + ) : this( + id, + _isMerge, + _mergePaths, + _objectDelete, + _parentId, + context, + created, + error, + expected, + input, + metadata, + metrics, + origin, + output, + rootSpanId, + scores, + spanAttributes, + spanId, + spanParents, + tags, + mutableMapOf(), + ) + /** * A unique identifier for the project logs event. If you don't provide one, BrainTrust will * generate one for you @@ -444,35 +471,15 @@ private constructor( */ @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): InsertProjectLogsEvent = apply { - if (validated) { - return@apply - } - - id() - _isMerge() - _mergePaths() - _objectDelete() - _parentId() - context().ifPresent { it.validate() } - created() - metadata().ifPresent { it.validate() } - metrics().ifPresent { it.validate() } - origin().ifPresent { it.validate() } - rootSpanId() - scores().ifPresent { it.validate() } - spanAttributes().ifPresent { it.validate() } - spanId() - spanParents() - tags() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1019,32 +1026,62 @@ private constructor( spanId, (spanParents ?: JsonMissing.of()).map { it.toImmutable() }, (tags ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): InsertProjectLogsEvent = apply { + if (validated) { + return@apply + } + + id() + _isMerge() + _mergePaths() + _objectDelete() + _parentId() + context().ifPresent { it.validate() } + created() + metadata().ifPresent { it.validate() } + metrics().ifPresent { it.validate() } + origin().ifPresent { it.validate() } + rootSpanId() + scores().ifPresent { it.validate() } + spanAttributes().ifPresent { it.validate() } + spanId() + spanParents() + tags() + validated = true + } + /** * Context is additional information about the code that produced the project logs event. It is * essentially the textual counterpart to `metrics`. Use the `caller_*` attributes to track the * location in code which produced the project logs event */ - @NoAutoDetect class Context - @JsonCreator private constructor( - @JsonProperty("caller_filename") - @ExcludeMissing - private val callerFilename: JsonField = JsonMissing.of(), - @JsonProperty("caller_functionname") - @ExcludeMissing - private val callerFunctionname: JsonField = JsonMissing.of(), - @JsonProperty("caller_lineno") - @ExcludeMissing - private val callerLineno: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val callerFilename: JsonField, + private val callerFunctionname: JsonField, + private val callerLineno: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("caller_filename") + @ExcludeMissing + callerFilename: JsonField = JsonMissing.of(), + @JsonProperty("caller_functionname") + @ExcludeMissing + callerFunctionname: JsonField = JsonMissing.of(), + @JsonProperty("caller_lineno") + @ExcludeMissing + callerLineno: JsonField = JsonMissing.of(), + ) : this(callerFilename, callerFunctionname, callerLineno, mutableMapOf()) + /** * Name of the file in code where the project logs event was created * @@ -1102,22 +1139,15 @@ private constructor( @ExcludeMissing fun _callerLineno(): JsonField = callerLineno + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Context = apply { - if (validated) { - return@apply - } - - callerFilename() - callerFunctionname() - callerLineno() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1237,10 +1267,23 @@ private constructor( callerFilename, callerFunctionname, callerLineno, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Context = apply { + if (validated) { + return@apply + } + + callerFilename() + callerFunctionname() + callerLineno() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1266,17 +1309,17 @@ private constructor( * slice/dice later. The values in `metadata` can be any JSON-serializable type, but its keys * must be strings */ - @NoAutoDetect class Metadata - @JsonCreator private constructor( - @JsonProperty("model") - @ExcludeMissing - private val model: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val model: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("model") @ExcludeMissing model: JsonField = JsonMissing.of() + ) : this(model, mutableMapOf()) + /** * The model used for this example * @@ -1292,20 +1335,15 @@ private constructor( */ @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - model() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1366,7 +1404,18 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(model, additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(model, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + model() + validated = true } override fun equals(other: Any?): Boolean { @@ -1392,36 +1441,51 @@ private constructor( * project logs event. Use "start" and "end" to track the time span over which the project logs * event was produced */ - @NoAutoDetect class Metrics - @JsonCreator private constructor( - @JsonProperty("caller_filename") - @ExcludeMissing - private val callerFilename: JsonValue = JsonMissing.of(), - @JsonProperty("caller_functionname") - @ExcludeMissing - private val callerFunctionname: JsonValue = JsonMissing.of(), - @JsonProperty("caller_lineno") - @ExcludeMissing - private val callerLineno: JsonValue = JsonMissing.of(), - @JsonProperty("completion_tokens") - @ExcludeMissing - private val completionTokens: JsonField = JsonMissing.of(), - @JsonProperty("end") @ExcludeMissing private val end: JsonField = JsonMissing.of(), - @JsonProperty("prompt_tokens") - @ExcludeMissing - private val promptTokens: JsonField = JsonMissing.of(), - @JsonProperty("start") - @ExcludeMissing - private val start: JsonField = JsonMissing.of(), - @JsonProperty("tokens") - @ExcludeMissing - private val tokens: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val callerFilename: JsonValue, + private val callerFunctionname: JsonValue, + private val callerLineno: JsonValue, + private val completionTokens: JsonField, + private val end: JsonField, + private val promptTokens: JsonField, + private val start: JsonField, + private val tokens: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("caller_filename") + @ExcludeMissing + callerFilename: JsonValue = JsonMissing.of(), + @JsonProperty("caller_functionname") + @ExcludeMissing + callerFunctionname: JsonValue = JsonMissing.of(), + @JsonProperty("caller_lineno") + @ExcludeMissing + callerLineno: JsonValue = JsonMissing.of(), + @JsonProperty("completion_tokens") + @ExcludeMissing + completionTokens: JsonField = JsonMissing.of(), + @JsonProperty("end") @ExcludeMissing end: JsonField = JsonMissing.of(), + @JsonProperty("prompt_tokens") + @ExcludeMissing + promptTokens: JsonField = JsonMissing.of(), + @JsonProperty("start") @ExcludeMissing start: JsonField = JsonMissing.of(), + @JsonProperty("tokens") @ExcludeMissing tokens: JsonField = JsonMissing.of(), + ) : this( + callerFilename, + callerFunctionname, + callerLineno, + completionTokens, + end, + promptTokens, + start, + tokens, + mutableMapOf(), + ) + /** This metric is deprecated */ @JsonProperty("caller_filename") @ExcludeMissing @@ -1522,24 +1586,15 @@ private constructor( */ @JsonProperty("tokens") @ExcludeMissing fun _tokens(): JsonField = tokens + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Metrics = apply { - if (validated) { - return@apply - } - - completionTokens() - end() - promptTokens() - start() - tokens() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1753,10 +1808,25 @@ private constructor( promptTokens, start, tokens, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Metrics = apply { + if (validated) { + return@apply + } + + completionTokens() + end() + promptTokens() + start() + tokens() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1784,27 +1854,20 @@ private constructor( * whether the summarization was covering similar concepts or not. You can use these scores to * help you sort, filter, and compare logs. */ - @NoAutoDetect class Scores - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Scores = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1848,7 +1911,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Scores = Scores(additionalProperties.toImmutable()) + fun build(): Scores = Scores(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Scores = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/MetricSummary.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/MetricSummary.kt index a6233247..55945097 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/MetricSummary.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/MetricSummary.kt @@ -6,38 +6,42 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional /** Summary of a metric's performance */ -@NoAutoDetect class MetricSummary -@JsonCreator private constructor( - @JsonProperty("improvements") - @ExcludeMissing - private val improvements: JsonField = JsonMissing.of(), - @JsonProperty("metric") - @ExcludeMissing - private val metric: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing private val name: JsonField = JsonMissing.of(), - @JsonProperty("regressions") - @ExcludeMissing - private val regressions: JsonField = JsonMissing.of(), - @JsonProperty("unit") @ExcludeMissing private val unit: JsonField = JsonMissing.of(), - @JsonProperty("diff") @ExcludeMissing private val diff: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val improvements: JsonField, + private val metric: JsonField, + private val name: JsonField, + private val regressions: JsonField, + private val unit: JsonField, + private val diff: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("improvements") + @ExcludeMissing + improvements: JsonField = JsonMissing.of(), + @JsonProperty("metric") @ExcludeMissing metric: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("regressions") + @ExcludeMissing + regressions: JsonField = JsonMissing.of(), + @JsonProperty("unit") @ExcludeMissing unit: JsonField = JsonMissing.of(), + @JsonProperty("diff") @ExcludeMissing diff: JsonField = JsonMissing.of(), + ) : this(improvements, metric, name, regressions, unit, diff, mutableMapOf()) + /** * Number of improvements in the metric * @@ -130,25 +134,15 @@ private constructor( */ @JsonProperty("diff") @ExcludeMissing fun _diff(): JsonField = diff + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): MetricSummary = apply { - if (validated) { - return@apply - } - - improvements() - metric() - name() - regressions() - unit() - diff() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -302,10 +296,26 @@ private constructor( checkRequired("regressions", regressions), checkRequired("unit", unit), diff, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): MetricSummary = apply { + if (validated) { + return@apply + } + + improvements() + metric() + name() + regressions() + unit() + diff() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ObjectReference.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ObjectReference.kt index 381f219f..aed4f93e 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ObjectReference.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ObjectReference.kt @@ -7,40 +7,39 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Indicates the event was copied from another object. */ -@NoAutoDetect class ObjectReference -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("_xact_id") - @ExcludeMissing - private val _xactId: JsonField = JsonMissing.of(), - @JsonProperty("object_id") - @ExcludeMissing - private val objectId: JsonField = JsonMissing.of(), - @JsonProperty("object_type") - @ExcludeMissing - private val objectType: JsonField = JsonMissing.of(), - @JsonProperty("created") - @ExcludeMissing - private val created: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val _xactId: JsonField, + private val objectId: JsonField, + private val objectType: JsonField, + private val created: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("_xact_id") @ExcludeMissing _xactId: JsonField = JsonMissing.of(), + @JsonProperty("object_id") @ExcludeMissing objectId: JsonField = JsonMissing.of(), + @JsonProperty("object_type") + @ExcludeMissing + objectType: JsonField = JsonMissing.of(), + @JsonProperty("created") @ExcludeMissing created: JsonField = JsonMissing.of(), + ) : this(id, _xactId, objectId, objectType, created, mutableMapOf()) + /** * ID of the original event. * @@ -118,24 +117,15 @@ private constructor( */ @JsonProperty("created") @ExcludeMissing fun _created(): JsonField = created + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): ObjectReference = apply { - if (validated) { - return@apply - } - - id() - _xactId() - objectId() - objectType() - created() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -275,10 +265,25 @@ private constructor( checkRequired("objectId", objectId), checkRequired("objectType", objectType), created, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): ObjectReference = apply { + if (validated) { + return@apply + } + + id() + _xactId() + objectId() + objectType() + created() + validated = true + } + /** Type of the object the event is originating from. */ class ObjectType @JsonCreator private constructor(private val value: JsonField) : Enum { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OnlineScoreConfig.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OnlineScoreConfig.kt index 22191392..7507d9e5 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OnlineScoreConfig.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OnlineScoreConfig.kt @@ -9,11 +9,9 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter @@ -27,29 +25,36 @@ import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class OnlineScoreConfig -@JsonCreator private constructor( - @JsonProperty("sampling_rate") - @ExcludeMissing - private val samplingRate: JsonField = JsonMissing.of(), - @JsonProperty("scorers") - @ExcludeMissing - private val scorers: JsonField> = JsonMissing.of(), - @JsonProperty("apply_to_root_span") - @ExcludeMissing - private val applyToRootSpan: JsonField = JsonMissing.of(), - @JsonProperty("apply_to_span_names") - @ExcludeMissing - private val applyToSpanNames: JsonField> = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val samplingRate: JsonField, + private val scorers: JsonField>, + private val applyToRootSpan: JsonField, + private val applyToSpanNames: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("sampling_rate") + @ExcludeMissing + samplingRate: JsonField = JsonMissing.of(), + @JsonProperty("scorers") + @ExcludeMissing + scorers: JsonField> = JsonMissing.of(), + @JsonProperty("apply_to_root_span") + @ExcludeMissing + applyToRootSpan: JsonField = JsonMissing.of(), + @JsonProperty("apply_to_span_names") + @ExcludeMissing + applyToSpanNames: JsonField> = JsonMissing.of(), + ) : this(samplingRate, scorers, applyToRootSpan, applyToSpanNames, mutableMapOf()) + /** * The sampling rate for online scoring * @@ -119,23 +124,15 @@ private constructor( @ExcludeMissing fun _applyToSpanNames(): JsonField> = applyToSpanNames + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): OnlineScoreConfig = apply { - if (validated) { - return@apply - } - - samplingRate() - scorers().forEach { it.validate() } - applyToRootSpan() - applyToSpanNames() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -312,10 +309,24 @@ private constructor( checkRequired("scorers", scorers).map { it.toImmutable() }, applyToRootSpan, (applyToSpanNames ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): OnlineScoreConfig = apply { + if (validated) { + return@apply + } + + samplingRate() + scorers().forEach { it.validate() } + applyToRootSpan() + applyToSpanNames() + validated = true + } + @JsonDeserialize(using = Scorer.Deserializer::class) @JsonSerialize(using = Scorer.Serializer::class) class Scorer @@ -449,20 +460,19 @@ private constructor( } } - @NoAutoDetect class Function - @JsonCreator private constructor( - @JsonProperty("id") - @ExcludeMissing - private val id: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(id, type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -491,21 +501,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Function = apply { - if (validated) { - return@apply - } - - id() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -598,10 +602,22 @@ private constructor( Function( checkRequired("id", id), checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Function = apply { + if (validated) { + return@apply + } + + id() + type() + validated = true + } + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -717,20 +733,19 @@ private constructor( "Function{id=$id, type=$type, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Global - @JsonCreator private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val name: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(name, type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -759,21 +774,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Global = apply { - if (validated) { - return@apply - } - - name() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -866,10 +875,22 @@ private constructor( Global( checkRequired("name", name), checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Global = apply { + if (validated) { + return@apply + } + + name() + type() + validated = true + } + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Organization.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Organization.kt index 532da10b..0c3299cf 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Organization.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Organization.kt @@ -6,44 +6,47 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class Organization -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing private val name: JsonField = JsonMissing.of(), - @JsonProperty("api_url") - @ExcludeMissing - private val apiUrl: JsonField = JsonMissing.of(), - @JsonProperty("created") - @ExcludeMissing - private val created: JsonField = JsonMissing.of(), - @JsonProperty("is_universal_api") - @ExcludeMissing - private val isUniversalApi: JsonField = JsonMissing.of(), - @JsonProperty("proxy_url") - @ExcludeMissing - private val proxyUrl: JsonField = JsonMissing.of(), - @JsonProperty("realtime_url") - @ExcludeMissing - private val realtimeUrl: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val name: JsonField, + private val apiUrl: JsonField, + private val created: JsonField, + private val isUniversalApi: JsonField, + private val proxyUrl: JsonField, + private val realtimeUrl: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("api_url") @ExcludeMissing apiUrl: JsonField = JsonMissing.of(), + @JsonProperty("created") + @ExcludeMissing + created: JsonField = JsonMissing.of(), + @JsonProperty("is_universal_api") + @ExcludeMissing + isUniversalApi: JsonField = JsonMissing.of(), + @JsonProperty("proxy_url") @ExcludeMissing proxyUrl: JsonField = JsonMissing.of(), + @JsonProperty("realtime_url") + @ExcludeMissing + realtimeUrl: JsonField = JsonMissing.of(), + ) : this(id, name, apiUrl, created, isUniversalApi, proxyUrl, realtimeUrl, mutableMapOf()) + /** * Unique identifier for the organization * @@ -147,26 +150,15 @@ private constructor( @ExcludeMissing fun _realtimeUrl(): JsonField = realtimeUrl + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Organization = apply { - if (validated) { - return@apply - } - - id() - name() - apiUrl() - created() - isUniversalApi() - proxyUrl() - realtimeUrl() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -351,10 +343,27 @@ private constructor( isUniversalApi, proxyUrl, realtimeUrl, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Organization = apply { + if (validated) { + return@apply + } + + id() + name() + apiUrl() + created() + isUniversalApi() + proxyUrl() + realtimeUrl() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationDeleteParams.kt index e543a1d3..eaaf6ad0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationDeleteParams.kt @@ -2,13 +2,15 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.toImmutable +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import java.util.Collections import java.util.Objects import java.util.Optional @@ -18,7 +20,7 @@ private constructor( private val organizationId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: Map, + private val additionalBodyProperties: MutableMap, ) : Params { /** Organization id */ @@ -28,21 +30,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _additionalBodyProperties(): Map = additionalBodyProperties - - @JvmSynthetic - internal fun _body(): Optional> = - Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - - fun _pathParam(index: Int): String = - when (index) { - 0 -> organizationId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders + @JsonAnySetter + private fun putAdditionalBodyProperty(key: String, value: JsonValue) { + additionalBodyProperties.put(key, value) + } - override fun _queryParams(): QueryParams = additionalQueryParams + @JsonAnyGetter + @ExcludeMissing + fun _additionalBodyProperties(): Map = + Collections.unmodifiableMap(additionalBodyProperties) fun toBuilder() = Builder().from(this) @@ -60,7 +56,6 @@ private constructor( } /** A builder for [OrganizationDeleteParams]. */ - @NoAutoDetect class Builder internal constructor() { private var organizationId: String? = null @@ -217,10 +212,24 @@ private constructor( checkRequired("organizationId", organizationId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toImmutable(), + additionalBodyProperties.toMutableMap(), ) } + @JvmSynthetic + internal fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> organizationId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt index 6683eed2..9d935959 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.blocking.OrganizationService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -90,24 +88,30 @@ private constructor( ) = OrganizationListPage(organizationsService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") - private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -165,7 +169,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt index 0c6503ba..7823eb8e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.async.OrganizationServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -92,24 +90,30 @@ private constructor( ) = OrganizationListPageAsync(organizationsService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") - private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -170,7 +174,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListParams.kt index ee4d5674..8a22272f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListParams.kt @@ -5,7 +5,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.BaseDeserializer import com.braintrustdata.api.core.BaseSerializer import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers @@ -71,30 +70,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = - QueryParams.builder() - .apply { - endingBefore?.let { put("ending_before", it) } - ids?.accept( - object : Ids.Visitor { - override fun visitString(string: String) { - put("ids", string) - } - - override fun visitStrings(strings: List) { - put("ids", strings.joinToString(",")) - } - } - ) - limit?.let { put("limit", it.toString()) } - orgName?.let { put("org_name", it) } - startingAfter?.let { put("starting_after", it) } - putAll(additionalQueryParams) - } - .build() - fun toBuilder() = Builder().from(this) companion object { @@ -106,7 +81,6 @@ private constructor( } /** A builder for [OrganizationListParams]. */ - @NoAutoDetect class Builder internal constructor() { private var endingBefore: String? = null @@ -302,6 +276,30 @@ private constructor( ) } + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + endingBefore?.let { put("ending_before", it) } + ids?.accept( + object : Ids.Visitor { + override fun visitString(string: String) { + put("ids", string) + } + + override fun visitStrings(strings: List) { + put("ids", strings.joinToString(",")) + } + } + ) + limit?.let { put("limit", it.toString()) } + orgName?.let { put("org_name", it) } + startingAfter?.let { put("starting_after", it) } + putAll(additionalQueryParams) + } + .build() + /** * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationMemberUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationMemberUpdateParams.kt index 11ffafd2..471b4675 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationMemberUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationMemberUpdateParams.kt @@ -6,18 +6,17 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -100,270 +99,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("invite_users") - @ExcludeMissing - private val inviteUsers: JsonField = JsonMissing.of(), - @JsonProperty("org_id") - @ExcludeMissing - private val orgId: JsonField = JsonMissing.of(), - @JsonProperty("org_name") - @ExcludeMissing - private val orgName: JsonField = JsonMissing.of(), - @JsonProperty("remove_users") - @ExcludeMissing - private val removeUsers: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { - - /** - * Users to invite to the organization - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun inviteUsers(): Optional = - Optional.ofNullable(inviteUsers.getNullable("invite_users")) - - /** - * For nearly all users, this parameter should be unnecessary. But in the rare case that - * your API key belongs to multiple organizations, or in case you want to explicitly assert - * the organization you are modifying, you may specify the id of the organization. - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun orgId(): Optional = Optional.ofNullable(orgId.getNullable("org_id")) - - /** - * For nearly all users, this parameter should be unnecessary. But in the rare case that - * your API key belongs to multiple organizations, or in case you want to explicitly assert - * the organization you are modifying, you may specify the name of the organization. - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) - - /** - * Users to remove from the organization - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun removeUsers(): Optional = - Optional.ofNullable(removeUsers.getNullable("remove_users")) - - /** - * Returns the raw JSON value of [inviteUsers]. - * - * Unlike [inviteUsers], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("invite_users") - @ExcludeMissing - fun _inviteUsers(): JsonField = inviteUsers - - /** - * Returns the raw JSON value of [orgId]. - * - * Unlike [orgId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("org_id") @ExcludeMissing fun _orgId(): JsonField = orgId - - /** - * Returns the raw JSON value of [orgName]. - * - * Unlike [orgName], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("org_name") @ExcludeMissing fun _orgName(): JsonField = orgName - - /** - * Returns the raw JSON value of [removeUsers]. - * - * Unlike [removeUsers], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("remove_users") - @ExcludeMissing - fun _removeUsers(): JsonField = removeUsers - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } - - inviteUsers().ifPresent { it.validate() } - orgId() - orgName() - removeUsers().ifPresent { it.validate() } - validated = true - } - - fun toBuilder() = Builder().from(this) - - companion object { - - /** Returns a mutable builder for constructing an instance of [Body]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var inviteUsers: JsonField = JsonMissing.of() - private var orgId: JsonField = JsonMissing.of() - private var orgName: JsonField = JsonMissing.of() - private var removeUsers: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - inviteUsers = body.inviteUsers - orgId = body.orgId - orgName = body.orgName - removeUsers = body.removeUsers - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** Users to invite to the organization */ - fun inviteUsers(inviteUsers: InviteUsers?) = - inviteUsers(JsonField.ofNullable(inviteUsers)) - - /** Alias for calling [Builder.inviteUsers] with `inviteUsers.orElse(null)`. */ - fun inviteUsers(inviteUsers: Optional) = - inviteUsers(inviteUsers.getOrNull()) - - /** - * Sets [Builder.inviteUsers] to an arbitrary JSON value. - * - * You should usually call [Builder.inviteUsers] with a well-typed [InviteUsers] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun inviteUsers(inviteUsers: JsonField) = apply { - this.inviteUsers = inviteUsers - } - - /** - * For nearly all users, this parameter should be unnecessary. But in the rare case that - * your API key belongs to multiple organizations, or in case you want to explicitly - * assert the organization you are modifying, you may specify the id of the - * organization. - */ - fun orgId(orgId: String?) = orgId(JsonField.ofNullable(orgId)) - - /** Alias for calling [Builder.orgId] with `orgId.orElse(null)`. */ - fun orgId(orgId: Optional) = orgId(orgId.getOrNull()) - - /** - * Sets [Builder.orgId] to an arbitrary JSON value. - * - * You should usually call [Builder.orgId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun orgId(orgId: JsonField) = apply { this.orgId = orgId } - - /** - * For nearly all users, this parameter should be unnecessary. But in the rare case that - * your API key belongs to multiple organizations, or in case you want to explicitly - * assert the organization you are modifying, you may specify the name of the - * organization. - */ - fun orgName(orgName: String?) = orgName(JsonField.ofNullable(orgName)) - - /** Alias for calling [Builder.orgName] with `orgName.orElse(null)`. */ - fun orgName(orgName: Optional) = orgName(orgName.getOrNull()) - - /** - * Sets [Builder.orgName] to an arbitrary JSON value. - * - * You should usually call [Builder.orgName] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun orgName(orgName: JsonField) = apply { this.orgName = orgName } - - /** Users to remove from the organization */ - fun removeUsers(removeUsers: RemoveUsers?) = - removeUsers(JsonField.ofNullable(removeUsers)) - - /** Alias for calling [Builder.removeUsers] with `removeUsers.orElse(null)`. */ - fun removeUsers(removeUsers: Optional) = - removeUsers(removeUsers.getOrNull()) - - /** - * Sets [Builder.removeUsers] to an arbitrary JSON value. - * - * You should usually call [Builder.removeUsers] with a well-typed [RemoveUsers] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun removeUsers(removeUsers: JsonField) = apply { - this.removeUsers = removeUsers - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - 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) - } - - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Body = - Body(inviteUsers, orgId, orgName, removeUsers, additionalProperties.toImmutable()) - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Body && inviteUsers == other.inviteUsers && orgId == other.orgId && orgName == other.orgName && removeUsers == other.removeUsers && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(inviteUsers, orgId, orgName, removeUsers, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Body{inviteUsers=$inviteUsers, orgId=$orgId, orgName=$orgName, removeUsers=$removeUsers, additionalProperties=$additionalProperties}" - } - fun toBuilder() = Builder().from(this) companion object { @@ -378,7 +113,6 @@ private constructor( } /** A builder for [OrganizationMemberUpdateParams]. */ - @NoAutoDetect class Builder internal constructor() { private var body: Body.Builder = Body.builder() @@ -486,142 +220,426 @@ private constructor( putAllAdditionalHeaders(additionalHeaders) } - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(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 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) + } + + /** + * Returns an immutable instance of [OrganizationMemberUpdateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): OrganizationMemberUpdateParams = + OrganizationMemberUpdateParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + @JvmSynthetic internal fun _body(): Body = body + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val inviteUsers: JsonField, + private val orgId: JsonField, + private val orgName: JsonField, + private val removeUsers: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("invite_users") + @ExcludeMissing + inviteUsers: JsonField = JsonMissing.of(), + @JsonProperty("org_id") @ExcludeMissing orgId: JsonField = JsonMissing.of(), + @JsonProperty("org_name") @ExcludeMissing orgName: JsonField = JsonMissing.of(), + @JsonProperty("remove_users") + @ExcludeMissing + removeUsers: JsonField = JsonMissing.of(), + ) : this(inviteUsers, orgId, orgName, removeUsers, mutableMapOf()) + + /** + * Users to invite to the organization + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun inviteUsers(): Optional = + Optional.ofNullable(inviteUsers.getNullable("invite_users")) + + /** + * For nearly all users, this parameter should be unnecessary. But in the rare case that + * your API key belongs to multiple organizations, or in case you want to explicitly assert + * the organization you are modifying, you may specify the id of the organization. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun orgId(): Optional = Optional.ofNullable(orgId.getNullable("org_id")) + + /** + * For nearly all users, this parameter should be unnecessary. But in the rare case that + * your API key belongs to multiple organizations, or in case you want to explicitly assert + * the organization you are modifying, you may specify the name of the organization. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) + + /** + * Users to remove from the organization + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun removeUsers(): Optional = + Optional.ofNullable(removeUsers.getNullable("remove_users")) + + /** + * Returns the raw JSON value of [inviteUsers]. + * + * Unlike [inviteUsers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("invite_users") + @ExcludeMissing + fun _inviteUsers(): JsonField = inviteUsers + + /** + * Returns the raw JSON value of [orgId]. + * + * Unlike [orgId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("org_id") @ExcludeMissing fun _orgId(): JsonField = orgId + + /** + * Returns the raw JSON value of [orgName]. + * + * Unlike [orgName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("org_name") @ExcludeMissing fun _orgName(): JsonField = orgName + + /** + * Returns the raw JSON value of [removeUsers]. + * + * Unlike [removeUsers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("remove_users") + @ExcludeMissing + fun _removeUsers(): JsonField = removeUsers + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Body]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var inviteUsers: JsonField = JsonMissing.of() + private var orgId: JsonField = JsonMissing.of() + private var orgName: JsonField = JsonMissing.of() + private var removeUsers: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + inviteUsers = body.inviteUsers + orgId = body.orgId + orgName = body.orgName + removeUsers = body.removeUsers + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** Users to invite to the organization */ + fun inviteUsers(inviteUsers: InviteUsers?) = + inviteUsers(JsonField.ofNullable(inviteUsers)) + + /** Alias for calling [Builder.inviteUsers] with `inviteUsers.orElse(null)`. */ + fun inviteUsers(inviteUsers: Optional) = + inviteUsers(inviteUsers.getOrNull()) + + /** + * Sets [Builder.inviteUsers] to an arbitrary JSON value. + * + * You should usually call [Builder.inviteUsers] with a well-typed [InviteUsers] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun inviteUsers(inviteUsers: JsonField) = apply { + this.inviteUsers = inviteUsers + } + + /** + * For nearly all users, this parameter should be unnecessary. But in the rare case that + * your API key belongs to multiple organizations, or in case you want to explicitly + * assert the organization you are modifying, you may specify the id of the + * organization. + */ + fun orgId(orgId: String?) = orgId(JsonField.ofNullable(orgId)) - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } + /** Alias for calling [Builder.orgId] with `orgId.orElse(null)`. */ + fun orgId(orgId: Optional) = orgId(orgId.getOrNull()) - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } + /** + * Sets [Builder.orgId] to an arbitrary JSON value. + * + * You should usually call [Builder.orgId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun orgId(orgId: JsonField) = apply { this.orgId = orgId } - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** + * For nearly all users, this parameter should be unnecessary. But in the rare case that + * your API key belongs to multiple organizations, or in case you want to explicitly + * assert the organization you are modifying, you may specify the name of the + * organization. + */ + fun orgName(orgName: String?) = orgName(JsonField.ofNullable(orgName)) - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** Alias for calling [Builder.orgName] with `orgName.orElse(null)`. */ + fun orgName(orgName: Optional) = orgName(orgName.getOrNull()) - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } + /** + * Sets [Builder.orgName] to an arbitrary JSON value. + * + * You should usually call [Builder.orgName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun orgName(orgName: JsonField) = apply { this.orgName = orgName } - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } + /** Users to remove from the organization */ + fun removeUsers(removeUsers: RemoveUsers?) = + removeUsers(JsonField.ofNullable(removeUsers)) - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** Alias for calling [Builder.removeUsers] with `removeUsers.orElse(null)`. */ + fun removeUsers(removeUsers: Optional) = + removeUsers(removeUsers.getOrNull()) - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** + * Sets [Builder.removeUsers] to an arbitrary JSON value. + * + * You should usually call [Builder.removeUsers] with a well-typed [RemoveUsers] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun removeUsers(removeUsers: JsonField) = apply { + this.removeUsers = removeUsers + } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Body = + Body(inviteUsers, orgId, orgName, removeUsers, additionalProperties.toMutableMap()) } - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } + private var validated: Boolean = false - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + fun validate(): Body = apply { + if (validated) { + return@apply } - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) + inviteUsers().ifPresent { it.validate() } + orgId() + orgName() + removeUsers().ifPresent { it.validate() } + validated = true } - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + return /* spotless:off */ other is Body && inviteUsers == other.inviteUsers && orgId == other.orgId && orgName == other.orgName && removeUsers == other.removeUsers && additionalProperties == other.additionalProperties /* spotless:on */ } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) - } - - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(inviteUsers, orgId, orgName, removeUsers, additionalProperties) } + /* spotless:on */ - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) - } + override fun hashCode(): Int = hashCode - /** - * Returns an immutable instance of [OrganizationMemberUpdateParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): OrganizationMemberUpdateParams = - OrganizationMemberUpdateParams( - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + override fun toString() = + "Body{inviteUsers=$inviteUsers, orgId=$orgId, orgName=$orgName, removeUsers=$removeUsers, additionalProperties=$additionalProperties}" } /** Users to invite to the organization */ - @NoAutoDetect class InviteUsers - @JsonCreator private constructor( - @JsonProperty("emails") - @ExcludeMissing - private val emails: JsonField> = JsonMissing.of(), - @JsonProperty("group_id") - @ExcludeMissing - private val groupId: JsonField = JsonMissing.of(), - @JsonProperty("group_ids") - @ExcludeMissing - private val groupIds: JsonField> = JsonMissing.of(), - @JsonProperty("group_name") - @ExcludeMissing - private val groupName: JsonField = JsonMissing.of(), - @JsonProperty("group_names") - @ExcludeMissing - private val groupNames: JsonField> = JsonMissing.of(), - @JsonProperty("ids") - @ExcludeMissing - private val ids: JsonField> = JsonMissing.of(), - @JsonProperty("send_invite_emails") - @ExcludeMissing - private val sendInviteEmails: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val emails: JsonField>, + private val groupId: JsonField, + private val groupIds: JsonField>, + private val groupName: JsonField, + private val groupNames: JsonField>, + private val ids: JsonField>, + private val sendInviteEmails: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("emails") + @ExcludeMissing + emails: JsonField> = JsonMissing.of(), + @JsonProperty("group_id") @ExcludeMissing groupId: JsonField = JsonMissing.of(), + @JsonProperty("group_ids") + @ExcludeMissing + groupIds: JsonField> = JsonMissing.of(), + @JsonProperty("group_name") + @ExcludeMissing + groupName: JsonField = JsonMissing.of(), + @JsonProperty("group_names") + @ExcludeMissing + groupNames: JsonField> = JsonMissing.of(), + @JsonProperty("ids") @ExcludeMissing ids: JsonField> = JsonMissing.of(), + @JsonProperty("send_invite_emails") + @ExcludeMissing + sendInviteEmails: JsonField = JsonMissing.of(), + ) : this( + emails, + groupId, + groupIds, + groupName, + groupNames, + ids, + sendInviteEmails, + mutableMapOf(), + ) + /** * Emails of users to invite * @@ -737,26 +755,15 @@ private constructor( @ExcludeMissing fun _sendInviteEmails(): JsonField = sendInviteEmails + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): InviteUsers = apply { - if (validated) { - return@apply - } - - emails() - groupId() - groupIds() - groupName() - groupNames() - ids() - sendInviteEmails() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -995,10 +1002,27 @@ private constructor( (groupNames ?: JsonMissing.of()).map { it.toImmutable() }, (ids ?: JsonMissing.of()).map { it.toImmutable() }, sendInviteEmails, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): InviteUsers = apply { + if (validated) { + return@apply + } + + emails() + groupId() + groupIds() + groupName() + groupNames() + ids() + sendInviteEmails() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1018,20 +1042,21 @@ private constructor( } /** Users to remove from the organization */ - @NoAutoDetect class RemoveUsers - @JsonCreator private constructor( - @JsonProperty("emails") - @ExcludeMissing - private val emails: JsonField> = JsonMissing.of(), - @JsonProperty("ids") - @ExcludeMissing - private val ids: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val emails: JsonField>, + private val ids: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("emails") + @ExcludeMissing + emails: JsonField> = JsonMissing.of(), + @JsonProperty("ids") @ExcludeMissing ids: JsonField> = JsonMissing.of(), + ) : this(emails, ids, mutableMapOf()) + /** * Emails of users to remove * @@ -1062,21 +1087,15 @@ private constructor( */ @JsonProperty("ids") @ExcludeMissing fun _ids(): JsonField> = ids + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): RemoveUsers = apply { - if (validated) { - return@apply - } - - emails() - ids() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1183,10 +1202,22 @@ private constructor( RemoveUsers( (emails ?: JsonMissing.of()).map { it.toImmutable() }, (ids ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): RemoveUsers = apply { + if (validated) { + return@apply + } + + emails() + ids() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationRetrieveParams.kt index e5c0ccc3..6be05478 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationRetrieveParams.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers @@ -24,16 +23,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _pathParam(index: Int): String = - when (index) { - 0 -> organizationId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - fun toBuilder() = Builder().from(this) companion object { @@ -50,7 +39,6 @@ private constructor( } /** A builder for [OrganizationRetrieveParams]. */ - @NoAutoDetect class Builder internal constructor() { private var organizationId: String? = null @@ -185,6 +173,16 @@ private constructor( ) } + fun _pathParam(index: Int): String = + when (index) { + 0 -> organizationId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationUpdateParams.kt index 3dae5442..3a60e7eb 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationUpdateParams.kt @@ -6,18 +6,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -111,197 +109,440 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body + fun toBuilder() = Builder().from(this) - fun _pathParam(index: Int): String = - when (index) { - 0 -> organizationId - else -> "" - } + companion object { - override fun _headers(): Headers = additionalHeaders + /** + * Returns a mutable builder for constructing an instance of [OrganizationUpdateParams]. + * + * The following fields are required: + * ```java + * .organizationId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun _queryParams(): QueryParams = additionalQueryParams + /** A builder for [OrganizationUpdateParams]. */ + class Builder internal constructor() { - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("api_url") - @ExcludeMissing - private val apiUrl: JsonField = JsonMissing.of(), - @JsonProperty("is_universal_api") - @ExcludeMissing - private val isUniversalApi: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("proxy_url") - @ExcludeMissing - private val proxyUrl: JsonField = JsonMissing.of(), - @JsonProperty("realtime_url") - @ExcludeMissing - private val realtimeUrl: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + private var organizationId: String? = null + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - /** - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun apiUrl(): Optional = Optional.ofNullable(apiUrl.getNullable("api_url")) + @JvmSynthetic + internal fun from(organizationUpdateParams: OrganizationUpdateParams) = apply { + organizationId = organizationUpdateParams.organizationId + body = organizationUpdateParams.body.toBuilder() + additionalHeaders = organizationUpdateParams.additionalHeaders.toBuilder() + additionalQueryParams = organizationUpdateParams.additionalQueryParams.toBuilder() + } - /** - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun isUniversalApi(): Optional = - Optional.ofNullable(isUniversalApi.getNullable("is_universal_api")) + /** Organization id */ + fun organizationId(organizationId: String) = apply { this.organizationId = organizationId } - /** - * Name of the organization - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun apiUrl(apiUrl: String?) = apply { body.apiUrl(apiUrl) } - /** - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun proxyUrl(): Optional = Optional.ofNullable(proxyUrl.getNullable("proxy_url")) + /** Alias for calling [Builder.apiUrl] with `apiUrl.orElse(null)`. */ + fun apiUrl(apiUrl: Optional) = apiUrl(apiUrl.getOrNull()) /** - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * Sets [Builder.apiUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.apiUrl] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun realtimeUrl(): Optional = - Optional.ofNullable(realtimeUrl.getNullable("realtime_url")) + fun apiUrl(apiUrl: JsonField) = apply { body.apiUrl(apiUrl) } + + fun isUniversalApi(isUniversalApi: Boolean?) = apply { body.isUniversalApi(isUniversalApi) } /** - * Returns the raw JSON value of [apiUrl]. + * Alias for [Builder.isUniversalApi]. * - * Unlike [apiUrl], this method doesn't throw if the JSON field has an unexpected type. + * This unboxed primitive overload exists for backwards compatibility. */ - @JsonProperty("api_url") @ExcludeMissing fun _apiUrl(): JsonField = apiUrl + fun isUniversalApi(isUniversalApi: Boolean) = isUniversalApi(isUniversalApi as Boolean?) + + /** Alias for calling [Builder.isUniversalApi] with `isUniversalApi.orElse(null)`. */ + fun isUniversalApi(isUniversalApi: Optional) = + isUniversalApi(isUniversalApi.getOrNull()) /** - * Returns the raw JSON value of [isUniversalApi]. + * Sets [Builder.isUniversalApi] to an arbitrary JSON value. * - * Unlike [isUniversalApi], this method doesn't throw if the JSON field has an unexpected - * type. + * You should usually call [Builder.isUniversalApi] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("is_universal_api") - @ExcludeMissing - fun _isUniversalApi(): JsonField = isUniversalApi + fun isUniversalApi(isUniversalApi: JsonField) = apply { + body.isUniversalApi(isUniversalApi) + } + + /** Name of the organization */ + fun name(name: String?) = apply { body.name(name) } + + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) /** - * Returns the raw JSON value of [name]. + * Sets [Builder.name] to an arbitrary JSON value. * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + fun name(name: JsonField) = apply { body.name(name) } + + fun proxyUrl(proxyUrl: String?) = apply { body.proxyUrl(proxyUrl) } + + /** Alias for calling [Builder.proxyUrl] with `proxyUrl.orElse(null)`. */ + fun proxyUrl(proxyUrl: Optional) = proxyUrl(proxyUrl.getOrNull()) /** - * Returns the raw JSON value of [proxyUrl]. + * Sets [Builder.proxyUrl] to an arbitrary JSON value. * - * Unlike [proxyUrl], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.proxyUrl] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("proxy_url") @ExcludeMissing fun _proxyUrl(): JsonField = proxyUrl + fun proxyUrl(proxyUrl: JsonField) = apply { body.proxyUrl(proxyUrl) } + + fun realtimeUrl(realtimeUrl: String?) = apply { body.realtimeUrl(realtimeUrl) } + + /** Alias for calling [Builder.realtimeUrl] with `realtimeUrl.orElse(null)`. */ + fun realtimeUrl(realtimeUrl: Optional) = realtimeUrl(realtimeUrl.getOrNull()) /** - * Returns the raw JSON value of [realtimeUrl]. + * Sets [Builder.realtimeUrl] to an arbitrary JSON value. * - * Unlike [realtimeUrl], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.realtimeUrl] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("realtime_url") - @ExcludeMissing - fun _realtimeUrl(): JsonField = realtimeUrl + fun realtimeUrl(realtimeUrl: JsonField) = apply { body.realtimeUrl(realtimeUrl) } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } - private var validated: Boolean = false + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } - fun validate(): Body = apply { - if (validated) { - return@apply + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) } - apiUrl() - isUniversalApi() - name() - proxyUrl() - realtimeUrl() - validated = true + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) } - fun toBuilder() = Builder().from(this) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - companion object { + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** Returns a mutable builder for constructing an instance of [Body]. */ - @JvmStatic fun builder() = Builder() + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - /** A builder for [Body]. */ - class Builder internal constructor() { + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - private var apiUrl: JsonField = JsonMissing.of() - private var isUniversalApi: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var proxyUrl: JsonField = JsonMissing.of() - private var realtimeUrl: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - @JvmSynthetic - internal fun from(body: Body) = apply { - apiUrl = body.apiUrl - isUniversalApi = body.isUniversalApi - name = body.name - proxyUrl = body.proxyUrl - realtimeUrl = body.realtimeUrl - additionalProperties = body.additionalProperties.toMutableMap() - } + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - fun apiUrl(apiUrl: String?) = apiUrl(JsonField.ofNullable(apiUrl)) + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - /** Alias for calling [Builder.apiUrl] with `apiUrl.orElse(null)`. */ - fun apiUrl(apiUrl: Optional) = apiUrl(apiUrl.getOrNull()) + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** - * Sets [Builder.apiUrl] to an arbitrary JSON value. - * - * You should usually call [Builder.apiUrl] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun apiUrl(apiUrl: JsonField) = apply { this.apiUrl = apiUrl } + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - fun isUniversalApi(isUniversalApi: Boolean?) = - isUniversalApi(JsonField.ofNullable(isUniversalApi)) + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Alias for [Builder.isUniversalApi]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun isUniversalApi(isUniversalApi: Boolean) = isUniversalApi(isUniversalApi as Boolean?) + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } - /** Alias for calling [Builder.isUniversalApi] with `isUniversalApi.orElse(null)`. */ - fun isUniversalApi(isUniversalApi: Optional) = - isUniversalApi(isUniversalApi.getOrNull()) + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } - /** - * Sets [Builder.isUniversalApi] to an arbitrary JSON value. - * - * You should usually call [Builder.isUniversalApi] with a well-typed [Boolean] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ + 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) + } + + /** + * Returns an immutable instance of [OrganizationUpdateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .organizationId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationUpdateParams = + OrganizationUpdateParams( + checkRequired("organizationId", organizationId), + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + @JvmSynthetic internal fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> organizationId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val apiUrl: JsonField, + private val isUniversalApi: JsonField, + private val name: JsonField, + private val proxyUrl: JsonField, + private val realtimeUrl: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("api_url") @ExcludeMissing apiUrl: JsonField = JsonMissing.of(), + @JsonProperty("is_universal_api") + @ExcludeMissing + isUniversalApi: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("proxy_url") + @ExcludeMissing + proxyUrl: JsonField = JsonMissing.of(), + @JsonProperty("realtime_url") + @ExcludeMissing + realtimeUrl: JsonField = JsonMissing.of(), + ) : this(apiUrl, isUniversalApi, name, proxyUrl, realtimeUrl, mutableMapOf()) + + /** + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun apiUrl(): Optional = Optional.ofNullable(apiUrl.getNullable("api_url")) + + /** + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun isUniversalApi(): Optional = + Optional.ofNullable(isUniversalApi.getNullable("is_universal_api")) + + /** + * Name of the organization + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + /** + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun proxyUrl(): Optional = Optional.ofNullable(proxyUrl.getNullable("proxy_url")) + + /** + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun realtimeUrl(): Optional = + Optional.ofNullable(realtimeUrl.getNullable("realtime_url")) + + /** + * Returns the raw JSON value of [apiUrl]. + * + * Unlike [apiUrl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("api_url") @ExcludeMissing fun _apiUrl(): JsonField = apiUrl + + /** + * Returns the raw JSON value of [isUniversalApi]. + * + * Unlike [isUniversalApi], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("is_universal_api") + @ExcludeMissing + fun _isUniversalApi(): JsonField = isUniversalApi + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [proxyUrl]. + * + * Unlike [proxyUrl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("proxy_url") @ExcludeMissing fun _proxyUrl(): JsonField = proxyUrl + + /** + * Returns the raw JSON value of [realtimeUrl]. + * + * Unlike [realtimeUrl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("realtime_url") + @ExcludeMissing + fun _realtimeUrl(): JsonField = realtimeUrl + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Body]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var apiUrl: JsonField = JsonMissing.of() + private var isUniversalApi: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var proxyUrl: JsonField = JsonMissing.of() + private var realtimeUrl: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + apiUrl = body.apiUrl + isUniversalApi = body.isUniversalApi + name = body.name + proxyUrl = body.proxyUrl + realtimeUrl = body.realtimeUrl + additionalProperties = body.additionalProperties.toMutableMap() + } + + fun apiUrl(apiUrl: String?) = apiUrl(JsonField.ofNullable(apiUrl)) + + /** Alias for calling [Builder.apiUrl] with `apiUrl.orElse(null)`. */ + fun apiUrl(apiUrl: Optional) = apiUrl(apiUrl.getOrNull()) + + /** + * Sets [Builder.apiUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.apiUrl] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun apiUrl(apiUrl: JsonField) = apply { this.apiUrl = apiUrl } + + fun isUniversalApi(isUniversalApi: Boolean?) = + isUniversalApi(JsonField.ofNullable(isUniversalApi)) + + /** + * Alias for [Builder.isUniversalApi]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun isUniversalApi(isUniversalApi: Boolean) = isUniversalApi(isUniversalApi as Boolean?) + + /** Alias for calling [Builder.isUniversalApi] with `isUniversalApi.orElse(null)`. */ + fun isUniversalApi(isUniversalApi: Optional) = + isUniversalApi(isUniversalApi.getOrNull()) + + /** + * Sets [Builder.isUniversalApi] to an arbitrary JSON value. + * + * You should usually call [Builder.isUniversalApi] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ fun isUniversalApi(isUniversalApi: JsonField) = apply { this.isUniversalApi = isUniversalApi } @@ -382,10 +623,25 @@ private constructor( name, proxyUrl, realtimeUrl, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + apiUrl() + isUniversalApi() + name() + proxyUrl() + realtimeUrl() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -404,257 +660,6 @@ private constructor( "Body{apiUrl=$apiUrl, isUniversalApi=$isUniversalApi, name=$name, proxyUrl=$proxyUrl, realtimeUrl=$realtimeUrl, additionalProperties=$additionalProperties}" } - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [OrganizationUpdateParams]. - * - * The following fields are required: - * ```java - * .organizationId() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [OrganizationUpdateParams]. */ - @NoAutoDetect - class Builder internal constructor() { - - private var organizationId: String? = null - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - - @JvmSynthetic - internal fun from(organizationUpdateParams: OrganizationUpdateParams) = apply { - organizationId = organizationUpdateParams.organizationId - body = organizationUpdateParams.body.toBuilder() - additionalHeaders = organizationUpdateParams.additionalHeaders.toBuilder() - additionalQueryParams = organizationUpdateParams.additionalQueryParams.toBuilder() - } - - /** Organization id */ - fun organizationId(organizationId: String) = apply { this.organizationId = organizationId } - - fun apiUrl(apiUrl: String?) = apply { body.apiUrl(apiUrl) } - - /** Alias for calling [Builder.apiUrl] with `apiUrl.orElse(null)`. */ - fun apiUrl(apiUrl: Optional) = apiUrl(apiUrl.getOrNull()) - - /** - * Sets [Builder.apiUrl] to an arbitrary JSON value. - * - * You should usually call [Builder.apiUrl] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun apiUrl(apiUrl: JsonField) = apply { body.apiUrl(apiUrl) } - - fun isUniversalApi(isUniversalApi: Boolean?) = apply { body.isUniversalApi(isUniversalApi) } - - /** - * Alias for [Builder.isUniversalApi]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun isUniversalApi(isUniversalApi: Boolean) = isUniversalApi(isUniversalApi as Boolean?) - - /** Alias for calling [Builder.isUniversalApi] with `isUniversalApi.orElse(null)`. */ - fun isUniversalApi(isUniversalApi: Optional) = - isUniversalApi(isUniversalApi.getOrNull()) - - /** - * Sets [Builder.isUniversalApi] to an arbitrary JSON value. - * - * You should usually call [Builder.isUniversalApi] with a well-typed [Boolean] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun isUniversalApi(isUniversalApi: JsonField) = apply { - body.isUniversalApi(isUniversalApi) - } - - /** Name of the organization */ - fun name(name: String?) = apply { body.name(name) } - - /** Alias for calling [Builder.name] with `name.orElse(null)`. */ - fun name(name: Optional) = name(name.getOrNull()) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun name(name: JsonField) = apply { body.name(name) } - - fun proxyUrl(proxyUrl: String?) = apply { body.proxyUrl(proxyUrl) } - - /** Alias for calling [Builder.proxyUrl] with `proxyUrl.orElse(null)`. */ - fun proxyUrl(proxyUrl: Optional) = proxyUrl(proxyUrl.getOrNull()) - - /** - * Sets [Builder.proxyUrl] to an arbitrary JSON value. - * - * You should usually call [Builder.proxyUrl] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun proxyUrl(proxyUrl: JsonField) = apply { body.proxyUrl(proxyUrl) } - - fun realtimeUrl(realtimeUrl: String?) = apply { body.realtimeUrl(realtimeUrl) } - - /** Alias for calling [Builder.realtimeUrl] with `realtimeUrl.orElse(null)`. */ - fun realtimeUrl(realtimeUrl: Optional) = realtimeUrl(realtimeUrl.getOrNull()) - - /** - * Sets [Builder.realtimeUrl] to an arbitrary JSON value. - * - * You should usually call [Builder.realtimeUrl] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun realtimeUrl(realtimeUrl: JsonField) = apply { body.realtimeUrl(realtimeUrl) } - - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) - } - - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } - - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) - } - - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } - - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } - - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } - - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(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 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) - } - - /** - * Returns an immutable instance of [OrganizationUpdateParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .organizationId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): OrganizationUpdateParams = - OrganizationUpdateParams( - checkRequired("organizationId", organizationId), - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PatchOrganizationMembersOutput.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PatchOrganizationMembersOutput.kt index 7a4c2743..98a4db87 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PatchOrganizationMembersOutput.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PatchOrganizationMembersOutput.kt @@ -7,33 +7,34 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class PatchOrganizationMembersOutput -@JsonCreator private constructor( - @JsonProperty("org_id") @ExcludeMissing private val orgId: JsonField = JsonMissing.of(), - @JsonProperty("status") - @ExcludeMissing - private val status: JsonField = JsonMissing.of(), - @JsonProperty("send_email_error") - @ExcludeMissing - private val sendEmailError: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val orgId: JsonField, + private val status: JsonField, + private val sendEmailError: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("org_id") @ExcludeMissing orgId: JsonField = JsonMissing.of(), + @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + @JsonProperty("send_email_error") + @ExcludeMissing + sendEmailError: JsonField = JsonMissing.of(), + ) : this(orgId, status, sendEmailError, mutableMapOf()) + /** * The id of the org that was modified. * @@ -81,22 +82,15 @@ private constructor( @ExcludeMissing fun _sendEmailError(): JsonField = sendEmailError + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): PatchOrganizationMembersOutput = apply { - if (validated) { - return@apply - } - - orgId() - status() - sendEmailError() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -212,10 +206,23 @@ private constructor( checkRequired("orgId", orgId), checkRequired("status", status), sendEmailError, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): PatchOrganizationMembersOutput = apply { + if (validated) { + return@apply + } + + orgId() + status() + sendEmailError() + validated = true + } + class Status @JsonCreator private constructor(private val value: JsonField) : Enum { /** diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Project.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Project.kt index 3d0007dd..69083ba0 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Project.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Project.kt @@ -6,42 +6,47 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class Project -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing private val name: JsonField = JsonMissing.of(), - @JsonProperty("org_id") @ExcludeMissing private val orgId: JsonField = JsonMissing.of(), - @JsonProperty("created") - @ExcludeMissing - private val created: JsonField = JsonMissing.of(), - @JsonProperty("deleted_at") - @ExcludeMissing - private val deletedAt: JsonField = JsonMissing.of(), - @JsonProperty("settings") - @ExcludeMissing - private val settings: JsonField = JsonMissing.of(), - @JsonProperty("user_id") - @ExcludeMissing - private val userId: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val name: JsonField, + private val orgId: JsonField, + private val created: JsonField, + private val deletedAt: JsonField, + private val settings: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("org_id") @ExcludeMissing orgId: JsonField = JsonMissing.of(), + @JsonProperty("created") + @ExcludeMissing + created: JsonField = JsonMissing.of(), + @JsonProperty("deleted_at") + @ExcludeMissing + deletedAt: JsonField = JsonMissing.of(), + @JsonProperty("settings") + @ExcludeMissing + settings: JsonField = JsonMissing.of(), + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), + ) : this(id, name, orgId, created, deletedAt, settings, userId, mutableMapOf()) + /** * Unique identifier for the project * @@ -149,26 +154,15 @@ private constructor( */ @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Project = apply { - if (validated) { - return@apply - } - - id() - name() - orgId() - created() - deletedAt() - settings().ifPresent { it.validate() } - userId() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -344,10 +338,27 @@ private constructor( deletedAt, settings, userId, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Project = apply { + if (validated) { + return@apply + } + + id() + name() + orgId() + created() + deletedAt() + settings().ifPresent { it.validate() } + userId() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectCreateParams.kt index 25f67ec7..5646004c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectCreateParams.kt @@ -6,18 +6,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -71,187 +69,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("org_name") - @ExcludeMissing - private val orgName: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { - - /** - * Name of the project - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun name(): String = name.getRequired("name") - - /** - * For nearly all users, this parameter should be unnecessary. But in the rare case that - * your API key belongs to multiple organizations, you may specify the name of the - * organization the project belongs in. - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) - - /** - * Returns the raw JSON value of [name]. - * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - - /** - * Returns the raw JSON value of [orgName]. - * - * Unlike [orgName], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("org_name") @ExcludeMissing fun _orgName(): JsonField = orgName - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } - - name() - orgName() - validated = true - } - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .name() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var name: JsonField? = null - private var orgName: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - name = body.name - orgName = body.orgName - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** Name of the project */ - fun name(name: String) = name(JsonField.of(name)) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } - - /** - * For nearly all users, this parameter should be unnecessary. But in the rare case that - * your API key belongs to multiple organizations, you may specify the name of the - * organization the project belongs in. - */ - fun orgName(orgName: String?) = orgName(JsonField.ofNullable(orgName)) - - /** Alias for calling [Builder.orgName] with `orgName.orElse(null)`. */ - fun orgName(orgName: Optional) = orgName(orgName.getOrNull()) - - /** - * Sets [Builder.orgName] to an arbitrary JSON value. - * - * You should usually call [Builder.orgName] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun orgName(orgName: JsonField) = apply { this.orgName = orgName } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - 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) - } - - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body(checkRequired("name", name), orgName, additionalProperties.toImmutable()) - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Body && name == other.name && orgName == other.orgName && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, orgName, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Body{name=$name, orgName=$orgName, additionalProperties=$additionalProperties}" - } - fun toBuilder() = Builder().from(this) companion object { @@ -268,7 +85,6 @@ private constructor( } /** A builder for [ProjectCreateParams]. */ - @NoAutoDetect class Builder internal constructor() { private var body: Body.Builder = Body.builder() @@ -448,6 +264,192 @@ private constructor( ) } + @JvmSynthetic internal fun _body(): Body = body + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val name: JsonField, + private val orgName: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("org_name") @ExcludeMissing orgName: JsonField = JsonMissing.of(), + ) : this(name, orgName, mutableMapOf()) + + /** + * Name of the project + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * For nearly all users, this parameter should be unnecessary. But in the rare case that + * your API key belongs to multiple organizations, you may specify the name of the + * organization the project belongs in. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [orgName]. + * + * Unlike [orgName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("org_name") @ExcludeMissing fun _orgName(): JsonField = orgName + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var name: JsonField? = null + private var orgName: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + name = body.name + orgName = body.orgName + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** Name of the project */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** + * For nearly all users, this parameter should be unnecessary. But in the rare case that + * your API key belongs to multiple organizations, you may specify the name of the + * organization the project belongs in. + */ + fun orgName(orgName: String?) = orgName(JsonField.ofNullable(orgName)) + + /** Alias for calling [Builder.orgName] with `orgName.orElse(null)`. */ + fun orgName(orgName: Optional) = orgName(orgName.getOrNull()) + + /** + * Sets [Builder.orgName] to an arbitrary JSON value. + * + * You should usually call [Builder.orgName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun orgName(orgName: JsonField) = apply { this.orgName = orgName } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body(checkRequired("name", name), orgName, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + name() + orgName() + validated = true + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && name == other.name && orgName == other.orgName && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(name, orgName, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{name=$name, orgName=$orgName, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectDeleteParams.kt index d537bce8..7b46451b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectDeleteParams.kt @@ -2,13 +2,15 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.toImmutable +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import java.util.Collections import java.util.Objects import java.util.Optional @@ -18,7 +20,7 @@ private constructor( private val projectId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: Map, + private val additionalBodyProperties: MutableMap, ) : Params { /** Project id */ @@ -28,21 +30,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _additionalBodyProperties(): Map = additionalBodyProperties - - @JvmSynthetic - internal fun _body(): Optional> = - Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - - fun _pathParam(index: Int): String = - when (index) { - 0 -> projectId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders + @JsonAnySetter + private fun putAdditionalBodyProperty(key: String, value: JsonValue) { + additionalBodyProperties.put(key, value) + } - override fun _queryParams(): QueryParams = additionalQueryParams + @JsonAnyGetter + @ExcludeMissing + fun _additionalBodyProperties(): Map = + Collections.unmodifiableMap(additionalBodyProperties) fun toBuilder() = Builder().from(this) @@ -60,7 +56,6 @@ private constructor( } /** A builder for [ProjectDeleteParams]. */ - @NoAutoDetect class Builder internal constructor() { private var projectId: String? = null @@ -216,10 +211,24 @@ private constructor( checkRequired("projectId", projectId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toImmutable(), + additionalBodyProperties.toMutableMap(), ) } + @JvmSynthetic + internal fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> projectId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPage.kt index 1d934cf4..2fe8b5d0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPage.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.blocking.ProjectService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -87,23 +85,30 @@ private constructor( ProjectListPage(projectsService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -161,7 +166,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageAsync.kt index f206043f..07c848e1 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageAsync.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.async.ProjectServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -92,23 +90,30 @@ private constructor( ) = ProjectListPageAsync(projectsService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -166,7 +171,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListParams.kt index 6b30061c..a30805f6 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListParams.kt @@ -5,7 +5,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.BaseDeserializer import com.braintrustdata.api.core.BaseSerializer import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers @@ -75,31 +74,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = - QueryParams.builder() - .apply { - endingBefore?.let { put("ending_before", it) } - ids?.accept( - object : Ids.Visitor { - override fun visitString(string: String) { - put("ids", string) - } - - override fun visitStrings(strings: List) { - put("ids", strings.joinToString(",")) - } - } - ) - limit?.let { put("limit", it.toString()) } - orgName?.let { put("org_name", it) } - projectName?.let { put("project_name", it) } - startingAfter?.let { put("starting_after", it) } - putAll(additionalQueryParams) - } - .build() - fun toBuilder() = Builder().from(this) companion object { @@ -111,7 +85,6 @@ private constructor( } /** A builder for [ProjectListParams]. */ - @NoAutoDetect class Builder internal constructor() { private var endingBefore: String? = null @@ -316,6 +289,31 @@ private constructor( ) } + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + endingBefore?.let { put("ending_before", it) } + ids?.accept( + object : Ids.Visitor { + override fun visitString(string: String) { + put("ids", string) + } + + override fun visitStrings(strings: List) { + put("ids", strings.joinToString(",")) + } + } + ) + limit?.let { put("limit", it.toString()) } + orgName?.let { put("org_name", it) } + projectName?.let { put("project_name", it) } + startingAfter?.let { put("starting_after", it) } + putAll(additionalQueryParams) + } + .build() + /** * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParams.kt index 13ff8992..79ab6c63 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParams.kt @@ -6,19 +6,18 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects /** Log feedback for a set of project logs events */ @@ -54,170 +53,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - fun _pathParam(index: Int): String = - when (index) { - 0 -> projectId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("feedback") - @ExcludeMissing - private val feedback: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { - - /** - * A list of project logs feedback items - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun feedback(): List = feedback.getRequired("feedback") - - /** - * Returns the raw JSON value of [feedback]. - * - * Unlike [feedback], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("feedback") - @ExcludeMissing - fun _feedback(): JsonField> = feedback - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } - - feedback().forEach { it.validate() } - validated = true - } - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .feedback() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var feedback: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - feedback = body.feedback.map { it.toMutableList() } - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** A list of project logs feedback items */ - fun feedback(feedback: List) = feedback(JsonField.of(feedback)) - - /** - * Sets [Builder.feedback] to an arbitrary JSON value. - * - * You should usually call [Builder.feedback] with a well-typed - * `List` value instead. This method is primarily for setting - * the field to an undocumented or not yet supported value. - */ - fun feedback(feedback: JsonField>) = apply { - this.feedback = feedback.map { it.toMutableList() } - } - - /** - * Adds a single [FeedbackProjectLogsItem] to [Builder.feedback]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addFeedback(feedback: FeedbackProjectLogsItem) = apply { - this.feedback = - (this.feedback ?: JsonField.of(mutableListOf())).also { - checkKnown("feedback", it).add(feedback) - } - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - 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) - } - - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .feedback() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("feedback", feedback).map { it.toImmutable() }, - additionalProperties.toImmutable(), - ) - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Body && feedback == other.feedback && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(feedback, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Body{feedback=$feedback, additionalProperties=$additionalProperties}" - } - fun toBuilder() = Builder().from(this) companion object { @@ -235,7 +70,6 @@ private constructor( } /** A builder for [ProjectLogFeedbackParams]. */ - @NoAutoDetect class Builder internal constructor() { private var projectId: String? = null @@ -414,6 +248,178 @@ private constructor( ) } + @JvmSynthetic internal fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> projectId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val feedback: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("feedback") + @ExcludeMissing + feedback: JsonField> = JsonMissing.of() + ) : this(feedback, mutableMapOf()) + + /** + * A list of project logs feedback items + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun feedback(): List = feedback.getRequired("feedback") + + /** + * Returns the raw JSON value of [feedback]. + * + * Unlike [feedback], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("feedback") + @ExcludeMissing + fun _feedback(): JsonField> = feedback + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .feedback() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var feedback: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + feedback = body.feedback.map { it.toMutableList() } + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** A list of project logs feedback items */ + fun feedback(feedback: List) = feedback(JsonField.of(feedback)) + + /** + * Sets [Builder.feedback] to an arbitrary JSON value. + * + * You should usually call [Builder.feedback] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun feedback(feedback: JsonField>) = apply { + this.feedback = feedback.map { it.toMutableList() } + } + + /** + * Adds a single [FeedbackProjectLogsItem] to [Builder.feedback]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addFeedback(feedback: FeedbackProjectLogsItem) = apply { + this.feedback = + (this.feedback ?: JsonField.of(mutableListOf())).also { + checkKnown("feedback", it).add(feedback) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .feedback() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("feedback", feedback).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + feedback().forEach { it.validate() } + validated = true + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && feedback == other.feedback && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(feedback, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{feedback=$feedback, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchParams.kt index faca3c10..3b8204f5 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchParams.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers @@ -86,25 +85,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _pathParam(index: Int): String = - when (index) { - 0 -> projectId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = - QueryParams.builder() - .apply { - limit?.let { put("limit", it.toString()) } - maxRootSpanId?.let { put("max_root_span_id", it) } - maxXactId?.let { put("max_xact_id", it) } - version?.let { put("version", it) } - putAll(additionalQueryParams) - } - .build() - fun toBuilder() = Builder().from(this) companion object { @@ -121,7 +101,6 @@ private constructor( } /** A builder for [ProjectLogFetchParams]. */ - @NoAutoDetect class Builder internal constructor() { private var projectId: String? = null @@ -341,6 +320,25 @@ private constructor( ) } + fun _pathParam(index: Int): String = + when (index) { + 0 -> projectId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + limit?.let { put("limit", it.toString()) } + maxRootSpanId?.let { put("max_root_span_id", it) } + maxXactId?.let { put("max_xact_id", it) } + version?.let { put("version", it) } + putAll(additionalQueryParams) + } + .build() + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParams.kt index 141ca6d9..ac207b10 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParams.kt @@ -6,18 +6,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -154,40 +152,39 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body + fun toBuilder() = Builder().from(this) - fun _pathParam(index: Int): String = - when (index) { - 0 -> projectId - else -> "" - } + companion object { - override fun _headers(): Headers = additionalHeaders + /** + * Returns a mutable builder for constructing an instance of [ProjectLogFetchPostParams]. + * + * The following fields are required: + * ```java + * .projectId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun _queryParams(): QueryParams = additionalQueryParams + /** A builder for [ProjectLogFetchPostParams]. */ + class Builder internal constructor() { - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("cursor") - @ExcludeMissing - private val cursor: JsonField = JsonMissing.of(), - @JsonProperty("limit") - @ExcludeMissing - private val limit: JsonField = JsonMissing.of(), - @JsonProperty("max_root_span_id") - @ExcludeMissing - private val maxRootSpanId: JsonField = JsonMissing.of(), - @JsonProperty("max_xact_id") - @ExcludeMissing - private val maxXactId: JsonField = JsonMissing.of(), - @JsonProperty("version") - @ExcludeMissing - private val version: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + private var projectId: String? = null + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(projectLogFetchPostParams: ProjectLogFetchPostParams) = apply { + projectId = projectLogFetchPostParams.projectId + body = projectLogFetchPostParams.body.toBuilder() + additionalHeaders = projectLogFetchPostParams.additionalHeaders.toBuilder() + additionalQueryParams = projectLogFetchPostParams.additionalQueryParams.toBuilder() + } + + /** Project id */ + fun projectId(projectId: String) = apply { this.projectId = projectId } /** * An opaque string to be used as a cursor for the next page of results, in order from @@ -195,11 +192,19 @@ private constructor( * * The string can be obtained directly from the `cursor` property of the previous fetch * query + */ + fun cursor(cursor: String?) = apply { body.cursor(cursor) } + + /** Alias for calling [Builder.cursor] with `cursor.orElse(null)`. */ + fun cursor(cursor: Optional) = cursor(cursor.getOrNull()) + + /** + * Sets [Builder.cursor] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.cursor] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun cursor(): Optional = Optional.ofNullable(cursor.getNullable("cursor")) + fun cursor(cursor: JsonField) = apply { body.cursor(cursor) } /** * limit the number of traces fetched @@ -215,11 +220,26 @@ private constructor( * The `limit` parameter controls the number of full traces to return. So you may end up * with more individual rows than the specified limit if you are fetching events containing * traces. + */ + fun limit(limit: Long?) = apply { body.limit(limit) } + + /** + * Alias for [Builder.limit]. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * This unboxed primitive overload exists for backwards compatibility. */ - fun limit(): Optional = Optional.ofNullable(limit.getNullable("limit")) + fun limit(limit: Long) = limit(limit as Long?) + + /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ + fun limit(limit: Optional) = limit(limit.getOrNull()) + + /** + * Sets [Builder.limit] to an arbitrary JSON value. + * + * You should usually call [Builder.limit] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun limit(limit: JsonField) = apply { body.limit(limit) } /** * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor of @@ -232,12 +252,23 @@ private constructor( * cursor for the next page can be found as the row with the minimum (earliest) value of the * tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an overview of * paginating fetch queries. + */ + fun maxRootSpanId(maxRootSpanId: String?) = apply { body.maxRootSpanId(maxRootSpanId) } + + /** Alias for calling [Builder.maxRootSpanId] with `maxRootSpanId.orElse(null)`. */ + fun maxRootSpanId(maxRootSpanId: Optional) = + maxRootSpanId(maxRootSpanId.getOrNull()) + + /** + * Sets [Builder.maxRootSpanId] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.maxRootSpanId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun maxRootSpanId(): Optional = - Optional.ofNullable(maxRootSpanId.getNullable("max_root_span_id")) + fun maxRootSpanId(maxRootSpanId: JsonField) = apply { + body.maxRootSpanId(maxRootSpanId) + } /** * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor of @@ -250,330 +281,212 @@ private constructor( * cursor for the next page can be found as the row with the minimum (earliest) value of the * tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an overview of * paginating fetch queries. + */ + fun maxXactId(maxXactId: String?) = apply { body.maxXactId(maxXactId) } + + /** Alias for calling [Builder.maxXactId] with `maxXactId.orElse(null)`. */ + fun maxXactId(maxXactId: Optional) = maxXactId(maxXactId.getOrNull()) + + /** + * Sets [Builder.maxXactId] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.maxXactId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun maxXactId(): Optional = - Optional.ofNullable(maxXactId.getNullable("max_xact_id")) + fun maxXactId(maxXactId: JsonField) = apply { body.maxXactId(maxXactId) } /** * Retrieve a snapshot of events from a past time * * The version id is essentially a filter on the latest event transaction id. You can use * the `max_xact_id` returned by a past fetch as the version to reproduce that exact fetch. - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). */ - fun version(): Optional = Optional.ofNullable(version.getNullable("version")) + fun version(version: String?) = apply { body.version(version) } - /** - * Returns the raw JSON value of [cursor]. - * - * Unlike [cursor], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("cursor") @ExcludeMissing fun _cursor(): JsonField = cursor + /** Alias for calling [Builder.version] with `version.orElse(null)`. */ + fun version(version: Optional) = version(version.getOrNull()) /** - * Returns the raw JSON value of [limit]. + * Sets [Builder.version] to an arbitrary JSON value. * - * Unlike [limit], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.version] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("limit") @ExcludeMissing fun _limit(): JsonField = limit + fun version(version: JsonField) = apply { body.version(version) } - /** - * Returns the raw JSON value of [maxRootSpanId]. - * - * Unlike [maxRootSpanId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("max_root_span_id") - @ExcludeMissing - fun _maxRootSpanId(): JsonField = maxRootSpanId + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } - /** - * Returns the raw JSON value of [maxXactId]. - * - * Unlike [maxXactId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("max_xact_id") @ExcludeMissing fun _maxXactId(): JsonField = maxXactId + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } - /** - * Returns the raw JSON value of [version]. - * - * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - private var validated: Boolean = false + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } - fun validate(): Body = apply { - if (validated) { - return@apply - } + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - cursor() - limit() - maxRootSpanId() - maxXactId() - version() - validated = true + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun toBuilder() = Builder().from(this) + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } - companion object { + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - /** Returns a mutable builder for constructing an instance of [Body]. */ - @JvmStatic fun builder() = Builder() + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } - /** A builder for [Body]. */ - class Builder internal constructor() { + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - private var cursor: JsonField = JsonMissing.of() - private var limit: JsonField = JsonMissing.of() - private var maxRootSpanId: JsonField = JsonMissing.of() - private var maxXactId: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - @JvmSynthetic - internal fun from(body: Body) = apply { - cursor = body.cursor - limit = body.limit - maxRootSpanId = body.maxRootSpanId - maxXactId = body.maxXactId - version = body.version - additionalProperties = body.additionalProperties.toMutableMap() - } + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** - * An opaque string to be used as a cursor for the next page of results, in order from - * latest to earliest. - * - * The string can be obtained directly from the `cursor` property of the previous fetch - * query - */ - fun cursor(cursor: String?) = cursor(JsonField.ofNullable(cursor)) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** Alias for calling [Builder.cursor] with `cursor.orElse(null)`. */ - fun cursor(cursor: Optional) = cursor(cursor.getOrNull()) + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Sets [Builder.cursor] to an arbitrary JSON value. - * - * You should usually call [Builder.cursor] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun cursor(cursor: JsonField) = apply { this.cursor = cursor } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } - /** - * limit the number of traces fetched - * - * Fetch queries may be paginated if the total result size is expected to be large (e.g. - * project_logs which accumulate over a long time). Note that fetch queries only support - * pagination in descending time order (from latest to earliest `_xact_id`. Furthermore, - * later pages may return rows which showed up in earlier pages, except with an earlier - * `_xact_id`. This happens because pagination occurs over the whole version history of - * the event log. You will most likely want to exclude any such duplicate, outdated rows - * (by `id`) from your combined result set. - * - * The `limit` parameter controls the number of full traces to return. So you may end up - * with more individual rows than the specified limit if you are fetching events - * containing traces. - */ - fun limit(limit: Long?) = limit(JsonField.ofNullable(limit)) - - /** - * Alias for [Builder.limit]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun limit(limit: Long) = limit(limit as Long?) - - /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ - fun limit(limit: Optional) = limit(limit.getOrNull()) - - /** - * Sets [Builder.limit] to an arbitrary JSON value. - * - * You should usually call [Builder.limit] with a well-typed [Long] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun limit(limit: JsonField) = apply { this.limit = limit } - - /** - * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor - * of the explicit 'cursor' returned by object fetch requests. Please prefer the - * 'cursor' argument going forwards. - * - * Together, `max_xact_id` and `max_root_span_id` form a pagination cursor - * - * Since a paginated fetch query returns results in order from latest to earliest, the - * cursor for the next page can be found as the row with the minimum (earliest) value of - * the tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an - * overview of paginating fetch queries. - */ - fun maxRootSpanId(maxRootSpanId: String?) = - maxRootSpanId(JsonField.ofNullable(maxRootSpanId)) - - /** Alias for calling [Builder.maxRootSpanId] with `maxRootSpanId.orElse(null)`. */ - fun maxRootSpanId(maxRootSpanId: Optional) = - maxRootSpanId(maxRootSpanId.getOrNull()) - - /** - * Sets [Builder.maxRootSpanId] to an arbitrary JSON value. - * - * You should usually call [Builder.maxRootSpanId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun maxRootSpanId(maxRootSpanId: JsonField) = apply { - this.maxRootSpanId = maxRootSpanId - } - - /** - * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor - * of the explicit 'cursor' returned by object fetch requests. Please prefer the - * 'cursor' argument going forwards. - * - * Together, `max_xact_id` and `max_root_span_id` form a pagination cursor - * - * Since a paginated fetch query returns results in order from latest to earliest, the - * cursor for the next page can be found as the row with the minimum (earliest) value of - * the tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an - * overview of paginating fetch queries. - */ - fun maxXactId(maxXactId: String?) = maxXactId(JsonField.ofNullable(maxXactId)) - - /** Alias for calling [Builder.maxXactId] with `maxXactId.orElse(null)`. */ - fun maxXactId(maxXactId: Optional) = maxXactId(maxXactId.getOrNull()) - - /** - * Sets [Builder.maxXactId] to an arbitrary JSON value. - * - * You should usually call [Builder.maxXactId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun maxXactId(maxXactId: JsonField) = apply { this.maxXactId = maxXactId } - - /** - * Retrieve a snapshot of events from a past time - * - * The version id is essentially a filter on the latest event transaction id. You can - * use the `max_xact_id` returned by a past fetch as the version to reproduce that exact - * fetch. - */ - fun version(version: String?) = version(JsonField.ofNullable(version)) - - /** Alias for calling [Builder.version] with `version.orElse(null)`. */ - fun version(version: Optional) = version(version.getOrNull()) - - /** - * Sets [Builder.version] to an arbitrary JSON value. - * - * You should usually call [Builder.version] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun version(version: JsonField) = apply { this.version = version } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Body = - Body( - cursor, - limit, - maxRootSpanId, - maxXactId, - version, - additionalProperties.toImmutable(), - ) + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - return /* spotless:off */ other is Body && cursor == other.cursor && limit == other.limit && maxRootSpanId == other.maxRootSpanId && maxXactId == other.maxXactId && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cursor, limit, maxRootSpanId, maxXactId, version, additionalProperties) } - /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } - override fun hashCode(): Int = hashCode + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - override fun toString() = - "Body{cursor=$cursor, limit=$limit, maxRootSpanId=$maxRootSpanId, maxXactId=$maxXactId, version=$version, additionalProperties=$additionalProperties}" - } + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - fun toBuilder() = Builder().from(this) + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - companion object { + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } /** - * Returns a mutable builder for constructing an instance of [ProjectLogFetchPostParams]. + * Returns an immutable instance of [ProjectLogFetchPostParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java * .projectId() * ``` + * + * @throws IllegalStateException if any required field is unset. */ - @JvmStatic fun builder() = Builder() + fun build(): ProjectLogFetchPostParams = + ProjectLogFetchPostParams( + checkRequired("projectId", projectId), + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) } - /** A builder for [ProjectLogFetchPostParams]. */ - @NoAutoDetect - class Builder internal constructor() { - - private var projectId: String? = null - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + @JvmSynthetic internal fun _body(): Body = body - @JvmSynthetic - internal fun from(projectLogFetchPostParams: ProjectLogFetchPostParams) = apply { - projectId = projectLogFetchPostParams.projectId - body = projectLogFetchPostParams.body.toBuilder() - additionalHeaders = projectLogFetchPostParams.additionalHeaders.toBuilder() - additionalQueryParams = projectLogFetchPostParams.additionalQueryParams.toBuilder() + fun _pathParam(index: Int): String = + when (index) { + 0 -> projectId + else -> "" } - /** Project id */ - fun projectId(projectId: String) = apply { this.projectId = projectId } + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val cursor: JsonField, + private val limit: JsonField, + private val maxRootSpanId: JsonField, + private val maxXactId: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cursor") @ExcludeMissing cursor: JsonField = JsonMissing.of(), + @JsonProperty("limit") @ExcludeMissing limit: JsonField = JsonMissing.of(), + @JsonProperty("max_root_span_id") + @ExcludeMissing + maxRootSpanId: JsonField = JsonMissing.of(), + @JsonProperty("max_xact_id") + @ExcludeMissing + maxXactId: JsonField = JsonMissing.of(), + @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), + ) : this(cursor, limit, maxRootSpanId, maxXactId, version, mutableMapOf()) /** * An opaque string to be used as a cursor for the next page of results, in order from @@ -581,19 +494,11 @@ private constructor( * * The string can be obtained directly from the `cursor` property of the previous fetch * query - */ - fun cursor(cursor: String?) = apply { body.cursor(cursor) } - - /** Alias for calling [Builder.cursor] with `cursor.orElse(null)`. */ - fun cursor(cursor: Optional) = cursor(cursor.getOrNull()) - - /** - * Sets [Builder.cursor] to an arbitrary JSON value. * - * You should usually call [Builder.cursor] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun cursor(cursor: JsonField) = apply { body.cursor(cursor) } + fun cursor(): Optional = Optional.ofNullable(cursor.getNullable("cursor")) /** * limit the number of traces fetched @@ -609,26 +514,29 @@ private constructor( * The `limit` parameter controls the number of full traces to return. So you may end up * with more individual rows than the specified limit if you are fetching events containing * traces. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun limit(limit: Long?) = apply { body.limit(limit) } + fun limit(): Optional = Optional.ofNullable(limit.getNullable("limit")) /** - * Alias for [Builder.limit]. + * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor of + * the explicit 'cursor' returned by object fetch requests. Please prefer the 'cursor' + * argument going forwards. * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun limit(limit: Long) = limit(limit as Long?) - - /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ - fun limit(limit: Optional) = limit(limit.getOrNull()) - - /** - * Sets [Builder.limit] to an arbitrary JSON value. + * Together, `max_xact_id` and `max_root_span_id` form a pagination cursor * - * You should usually call [Builder.limit] with a well-typed [Long] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Since a paginated fetch query returns results in order from latest to earliest, the + * cursor for the next page can be found as the row with the minimum (earliest) value of the + * tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an overview of + * paginating fetch queries. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun limit(limit: JsonField) = apply { body.limit(limit) } + fun maxRootSpanId(): Optional = + Optional.ofNullable(maxRootSpanId.getNullable("max_root_span_id")) /** * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor of @@ -641,205 +549,300 @@ private constructor( * cursor for the next page can be found as the row with the minimum (earliest) value of the * tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an overview of * paginating fetch queries. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun maxRootSpanId(maxRootSpanId: String?) = apply { body.maxRootSpanId(maxRootSpanId) } - - /** Alias for calling [Builder.maxRootSpanId] with `maxRootSpanId.orElse(null)`. */ - fun maxRootSpanId(maxRootSpanId: Optional) = - maxRootSpanId(maxRootSpanId.getOrNull()) + fun maxXactId(): Optional = + Optional.ofNullable(maxXactId.getNullable("max_xact_id")) /** - * Sets [Builder.maxRootSpanId] to an arbitrary JSON value. + * Retrieve a snapshot of events from a past time * - * You should usually call [Builder.maxRootSpanId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * The version id is essentially a filter on the latest event transaction id. You can use + * the `max_xact_id` returned by a past fetch as the version to reproduce that exact fetch. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun maxRootSpanId(maxRootSpanId: JsonField) = apply { - body.maxRootSpanId(maxRootSpanId) - } + fun version(): Optional = Optional.ofNullable(version.getNullable("version")) /** - * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor of - * the explicit 'cursor' returned by object fetch requests. Please prefer the 'cursor' - * argument going forwards. - * - * Together, `max_xact_id` and `max_root_span_id` form a pagination cursor + * Returns the raw JSON value of [cursor]. * - * Since a paginated fetch query returns results in order from latest to earliest, the - * cursor for the next page can be found as the row with the minimum (earliest) value of the - * tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an overview of - * paginating fetch queries. + * Unlike [cursor], this method doesn't throw if the JSON field has an unexpected type. */ - fun maxXactId(maxXactId: String?) = apply { body.maxXactId(maxXactId) } - - /** Alias for calling [Builder.maxXactId] with `maxXactId.orElse(null)`. */ - fun maxXactId(maxXactId: Optional) = maxXactId(maxXactId.getOrNull()) + @JsonProperty("cursor") @ExcludeMissing fun _cursor(): JsonField = cursor /** - * Sets [Builder.maxXactId] to an arbitrary JSON value. + * Returns the raw JSON value of [limit]. * - * You should usually call [Builder.maxXactId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [limit], this method doesn't throw if the JSON field has an unexpected type. */ - fun maxXactId(maxXactId: JsonField) = apply { body.maxXactId(maxXactId) } + @JsonProperty("limit") @ExcludeMissing fun _limit(): JsonField = limit /** - * Retrieve a snapshot of events from a past time + * Returns the raw JSON value of [maxRootSpanId]. * - * The version id is essentially a filter on the latest event transaction id. You can use - * the `max_xact_id` returned by a past fetch as the version to reproduce that exact fetch. + * Unlike [maxRootSpanId], this method doesn't throw if the JSON field has an unexpected + * type. */ - fun version(version: String?) = apply { body.version(version) } + @JsonProperty("max_root_span_id") + @ExcludeMissing + fun _maxRootSpanId(): JsonField = maxRootSpanId - /** Alias for calling [Builder.version] with `version.orElse(null)`. */ - fun version(version: Optional) = version(version.getOrNull()) + /** + * Returns the raw JSON value of [maxXactId]. + * + * Unlike [maxXactId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("max_xact_id") @ExcludeMissing fun _maxXactId(): JsonField = maxXactId /** - * Sets [Builder.version] to an arbitrary JSON value. + * Returns the raw JSON value of [version]. * - * You should usually call [Builder.version] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. */ - fun version(version: JsonField) = apply { body.version(version) } + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Body]. */ + @JvmStatic fun builder() = Builder() } - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var cursor: JsonField = JsonMissing.of() + private var limit: JsonField = JsonMissing.of() + private var maxRootSpanId: JsonField = JsonMissing.of() + private var maxXactId: JsonField = JsonMissing.of() + private var version: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + cursor = body.cursor + limit = body.limit + maxRootSpanId = body.maxRootSpanId + maxXactId = body.maxXactId + version = body.version + additionalProperties = body.additionalProperties.toMutableMap() } - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + /** + * An opaque string to be used as a cursor for the next page of results, in order from + * latest to earliest. + * + * The string can be obtained directly from the `cursor` property of the previous fetch + * query + */ + fun cursor(cursor: String?) = cursor(JsonField.ofNullable(cursor)) - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } + /** Alias for calling [Builder.cursor] with `cursor.orElse(null)`. */ + fun cursor(cursor: Optional) = cursor(cursor.getOrNull()) - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * Sets [Builder.cursor] to an arbitrary JSON value. + * + * You should usually call [Builder.cursor] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun cursor(cursor: JsonField) = apply { this.cursor = cursor } - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * limit the number of traces fetched + * + * Fetch queries may be paginated if the total result size is expected to be large (e.g. + * project_logs which accumulate over a long time). Note that fetch queries only support + * pagination in descending time order (from latest to earliest `_xact_id`. Furthermore, + * later pages may return rows which showed up in earlier pages, except with an earlier + * `_xact_id`. This happens because pagination occurs over the whole version history of + * the event log. You will most likely want to exclude any such duplicate, outdated rows + * (by `id`) from your combined result set. + * + * The `limit` parameter controls the number of full traces to return. So you may end up + * with more individual rows than the specified limit if you are fetching events + * containing traces. + */ + fun limit(limit: Long?) = limit(JsonField.ofNullable(limit)) - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } + /** + * Alias for [Builder.limit]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun limit(limit: Long) = limit(limit as Long?) - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } + /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ + fun limit(limit: Optional) = limit(limit.getOrNull()) - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** + * Sets [Builder.limit] to an arbitrary JSON value. + * + * You should usually call [Builder.limit] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun limit(limit: JsonField) = apply { this.limit = limit } - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** + * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor + * of the explicit 'cursor' returned by object fetch requests. Please prefer the + * 'cursor' argument going forwards. + * + * Together, `max_xact_id` and `max_root_span_id` form a pagination cursor + * + * Since a paginated fetch query returns results in order from latest to earliest, the + * cursor for the next page can be found as the row with the minimum (earliest) value of + * the tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an + * overview of paginating fetch queries. + */ + fun maxRootSpanId(maxRootSpanId: String?) = + maxRootSpanId(JsonField.ofNullable(maxRootSpanId)) - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } + /** Alias for calling [Builder.maxRootSpanId] with `maxRootSpanId.orElse(null)`. */ + fun maxRootSpanId(maxRootSpanId: Optional) = + maxRootSpanId(maxRootSpanId.getOrNull()) - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } + /** + * Sets [Builder.maxRootSpanId] to an arbitrary JSON value. + * + * You should usually call [Builder.maxRootSpanId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun maxRootSpanId(maxRootSpanId: JsonField) = apply { + this.maxRootSpanId = maxRootSpanId + } - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** + * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor + * of the explicit 'cursor' returned by object fetch requests. Please prefer the + * 'cursor' argument going forwards. + * + * Together, `max_xact_id` and `max_root_span_id` form a pagination cursor + * + * Since a paginated fetch query returns results in order from latest to earliest, the + * cursor for the next page can be found as the row with the minimum (earliest) value of + * the tuple `(_xact_id, root_span_id)`. See the documentation of `limit` for an + * overview of paginating fetch queries. + */ + fun maxXactId(maxXactId: String?) = maxXactId(JsonField.ofNullable(maxXactId)) - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** Alias for calling [Builder.maxXactId] with `maxXactId.orElse(null)`. */ + fun maxXactId(maxXactId: Optional) = maxXactId(maxXactId.getOrNull()) - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + /** + * Sets [Builder.maxXactId] to an arbitrary JSON value. + * + * You should usually call [Builder.maxXactId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun maxXactId(maxXactId: JsonField) = apply { this.maxXactId = maxXactId } - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } + /** + * Retrieve a snapshot of events from a past time + * + * The version id is essentially a filter on the latest event transaction id. You can + * use the `max_xact_id` returned by a past fetch as the version to reproduce that exact + * fetch. + */ + fun version(version: String?) = version(JsonField.ofNullable(version)) - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + /** Alias for calling [Builder.version] with `version.orElse(null)`. */ + fun version(version: Optional) = version(version.getOrNull()) - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + /** + * Sets [Builder.version] to an arbitrary JSON value. + * + * You should usually call [Builder.version] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun version(version: JsonField) = apply { this.version = version } - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Body = + Body( + cursor, + limit, + maxRootSpanId, + maxXactId, + version, + additionalProperties.toMutableMap(), + ) } - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } + private var validated: Boolean = false - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + fun validate(): Body = apply { + if (validated) { + return@apply + } + + cursor() + limit() + maxRootSpanId() + maxXactId() + version() + validated = true } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) + return /* spotless:off */ other is Body && cursor == other.cursor && limit == other.limit && maxRootSpanId == other.maxRootSpanId && maxXactId == other.maxXactId && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ } - /** - * Returns an immutable instance of [ProjectLogFetchPostParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .projectId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ProjectLogFetchPostParams = - ProjectLogFetchPostParams( - checkRequired("projectId", projectId), - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(cursor, limit, maxRootSpanId, maxXactId, version, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{cursor=$cursor, limit=$limit, maxRootSpanId=$maxRootSpanId, maxXactId=$maxXactId, version=$version, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogInsertParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogInsertParams.kt index e28846e1..aba94683 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogInsertParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogInsertParams.kt @@ -6,19 +6,18 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects /** Insert a set of events into the project logs */ @@ -54,169 +53,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - fun _pathParam(index: Int): String = - when (index) { - 0 -> projectId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("events") - @ExcludeMissing - private val events: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { - - /** - * A list of project logs events to insert - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun events(): List = events.getRequired("events") - - /** - * Returns the raw JSON value of [events]. - * - * Unlike [events], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("events") - @ExcludeMissing - fun _events(): JsonField> = events - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } - - events().forEach { it.validate() } - validated = true - } - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .events() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var events: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - events = body.events.map { it.toMutableList() } - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** A list of project logs events to insert */ - fun events(events: List) = events(JsonField.of(events)) - - /** - * Sets [Builder.events] to an arbitrary JSON value. - * - * You should usually call [Builder.events] with a well-typed - * `List` value instead. This method is primarily for setting - * the field to an undocumented or not yet supported value. - */ - fun events(events: JsonField>) = apply { - this.events = events.map { it.toMutableList() } - } - - /** - * Adds a single [InsertProjectLogsEvent] to [events]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addEvent(event: InsertProjectLogsEvent) = apply { - events = - (events ?: JsonField.of(mutableListOf())).also { - checkKnown("events", it).add(event) - } - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - 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) - } - - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .events() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("events", events).map { it.toImmutable() }, - additionalProperties.toImmutable(), - ) - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Body && events == other.events && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(events, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = "Body{events=$events, additionalProperties=$additionalProperties}" - } - fun toBuilder() = Builder().from(this) companion object { @@ -234,7 +70,6 @@ private constructor( } /** A builder for [ProjectLogInsertParams]. */ - @NoAutoDetect class Builder internal constructor() { private var projectId: String? = null @@ -411,6 +246,177 @@ private constructor( ) } + @JvmSynthetic internal fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> projectId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val events: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("events") + @ExcludeMissing + events: JsonField> = JsonMissing.of() + ) : this(events, mutableMapOf()) + + /** + * A list of project logs events to insert + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun events(): List = events.getRequired("events") + + /** + * Returns the raw JSON value of [events]. + * + * Unlike [events], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("events") + @ExcludeMissing + fun _events(): JsonField> = events + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .events() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var events: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + events = body.events.map { it.toMutableList() } + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** A list of project logs events to insert */ + fun events(events: List) = events(JsonField.of(events)) + + /** + * Sets [Builder.events] to an arbitrary JSON value. + * + * You should usually call [Builder.events] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun events(events: JsonField>) = apply { + this.events = events.map { it.toMutableList() } + } + + /** + * Adds a single [InsertProjectLogsEvent] to [events]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addEvent(event: InsertProjectLogsEvent) = apply { + events = + (events ?: JsonField.of(mutableListOf())).also { + checkKnown("events", it).add(event) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .events() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("events", events).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + events().forEach { it.validate() } + validated = true + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && events == other.events && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(events, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = "Body{events=$events, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogsEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogsEvent.kt index f4371612..f76bd22d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogsEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogsEvent.kt @@ -7,10 +7,8 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter @@ -18,66 +16,95 @@ import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class ProjectLogsEvent -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("_xact_id") - @ExcludeMissing - private val _xactId: JsonField = JsonMissing.of(), - @JsonProperty("created") - @ExcludeMissing - private val created: JsonField = JsonMissing.of(), - @JsonProperty("log_id") @ExcludeMissing private val logId: JsonField = JsonMissing.of(), - @JsonProperty("org_id") @ExcludeMissing private val orgId: JsonField = JsonMissing.of(), - @JsonProperty("project_id") - @ExcludeMissing - private val projectId: JsonField = JsonMissing.of(), - @JsonProperty("root_span_id") - @ExcludeMissing - private val rootSpanId: JsonField = JsonMissing.of(), - @JsonProperty("span_id") - @ExcludeMissing - private val spanId: JsonField = JsonMissing.of(), - @JsonProperty("context") - @ExcludeMissing - private val context: JsonField = JsonMissing.of(), - @JsonProperty("error") @ExcludeMissing private val error: JsonValue = JsonMissing.of(), - @JsonProperty("expected") @ExcludeMissing private val expected: JsonValue = JsonMissing.of(), - @JsonProperty("input") @ExcludeMissing private val input: JsonValue = JsonMissing.of(), - @JsonProperty("is_root") - @ExcludeMissing - private val isRoot: JsonField = JsonMissing.of(), - @JsonProperty("metadata") - @ExcludeMissing - private val metadata: JsonField = JsonMissing.of(), - @JsonProperty("metrics") - @ExcludeMissing - private val metrics: JsonField = JsonMissing.of(), - @JsonProperty("origin") - @ExcludeMissing - private val origin: JsonField = JsonMissing.of(), - @JsonProperty("output") @ExcludeMissing private val output: JsonValue = JsonMissing.of(), - @JsonProperty("scores") - @ExcludeMissing - private val scores: JsonField = JsonMissing.of(), - @JsonProperty("span_attributes") - @ExcludeMissing - private val spanAttributes: JsonField = JsonMissing.of(), - @JsonProperty("span_parents") - @ExcludeMissing - private val spanParents: JsonField> = JsonMissing.of(), - @JsonProperty("tags") - @ExcludeMissing - private val tags: JsonField> = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val _xactId: JsonField, + private val created: JsonField, + private val logId: JsonField, + private val orgId: JsonField, + private val projectId: JsonField, + private val rootSpanId: JsonField, + private val spanId: JsonField, + private val context: JsonField, + private val error: JsonValue, + private val expected: JsonValue, + private val input: JsonValue, + private val isRoot: JsonField, + private val metadata: JsonField, + private val metrics: JsonField, + private val origin: JsonField, + private val output: JsonValue, + private val scores: JsonField, + private val spanAttributes: JsonField, + private val spanParents: JsonField>, + private val tags: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("_xact_id") @ExcludeMissing _xactId: JsonField = JsonMissing.of(), + @JsonProperty("created") + @ExcludeMissing + created: JsonField = JsonMissing.of(), + @JsonProperty("log_id") @ExcludeMissing logId: JsonField = JsonMissing.of(), + @JsonProperty("org_id") @ExcludeMissing orgId: JsonField = JsonMissing.of(), + @JsonProperty("project_id") @ExcludeMissing projectId: JsonField = JsonMissing.of(), + @JsonProperty("root_span_id") + @ExcludeMissing + rootSpanId: JsonField = JsonMissing.of(), + @JsonProperty("span_id") @ExcludeMissing spanId: JsonField = JsonMissing.of(), + @JsonProperty("context") @ExcludeMissing context: JsonField = JsonMissing.of(), + @JsonProperty("error") @ExcludeMissing error: JsonValue = JsonMissing.of(), + @JsonProperty("expected") @ExcludeMissing expected: JsonValue = JsonMissing.of(), + @JsonProperty("input") @ExcludeMissing input: JsonValue = JsonMissing.of(), + @JsonProperty("is_root") @ExcludeMissing isRoot: JsonField = JsonMissing.of(), + @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("metrics") @ExcludeMissing metrics: JsonField = JsonMissing.of(), + @JsonProperty("origin") + @ExcludeMissing + origin: JsonField = JsonMissing.of(), + @JsonProperty("output") @ExcludeMissing output: JsonValue = JsonMissing.of(), + @JsonProperty("scores") @ExcludeMissing scores: JsonField = JsonMissing.of(), + @JsonProperty("span_attributes") + @ExcludeMissing + spanAttributes: JsonField = JsonMissing.of(), + @JsonProperty("span_parents") + @ExcludeMissing + spanParents: JsonField> = JsonMissing.of(), + @JsonProperty("tags") @ExcludeMissing tags: JsonField> = JsonMissing.of(), + ) : this( + id, + _xactId, + created, + logId, + orgId, + projectId, + rootSpanId, + spanId, + context, + error, + expected, + input, + isRoot, + metadata, + metrics, + origin, + output, + scores, + spanAttributes, + spanParents, + tags, + mutableMapOf(), + ) + /** * A unique identifier for the project logs event. If you don't provide one, BrainTrust will * generate one for you @@ -384,36 +411,15 @@ private constructor( */ @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): ProjectLogsEvent = apply { - if (validated) { - return@apply - } - - id() - _xactId() - created() - logId() - orgId() - projectId() - rootSpanId() - spanId() - context().ifPresent { it.validate() } - isRoot() - metadata().ifPresent { it.validate() } - metrics().ifPresent { it.validate() } - origin().ifPresent { it.validate() } - scores().ifPresent { it.validate() } - spanAttributes().ifPresent { it.validate() } - spanParents() - tags() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -872,10 +878,37 @@ private constructor( spanAttributes, (spanParents ?: JsonMissing.of()).map { it.toImmutable() }, (tags ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): ProjectLogsEvent = apply { + if (validated) { + return@apply + } + + id() + _xactId() + created() + logId() + orgId() + projectId() + rootSpanId() + spanId() + context().ifPresent { it.validate() } + isRoot() + metadata().ifPresent { it.validate() } + metrics().ifPresent { it.validate() } + origin().ifPresent { it.validate() } + scores().ifPresent { it.validate() } + spanAttributes().ifPresent { it.validate() } + spanParents() + tags() + validated = true + } + /** A literal 'g' which identifies the log as a project log */ class LogId @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -976,23 +1009,27 @@ private constructor( * essentially the textual counterpart to `metrics`. Use the `caller_*` attributes to track the * location in code which produced the project logs event */ - @NoAutoDetect class Context - @JsonCreator private constructor( - @JsonProperty("caller_filename") - @ExcludeMissing - private val callerFilename: JsonField = JsonMissing.of(), - @JsonProperty("caller_functionname") - @ExcludeMissing - private val callerFunctionname: JsonField = JsonMissing.of(), - @JsonProperty("caller_lineno") - @ExcludeMissing - private val callerLineno: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val callerFilename: JsonField, + private val callerFunctionname: JsonField, + private val callerLineno: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("caller_filename") + @ExcludeMissing + callerFilename: JsonField = JsonMissing.of(), + @JsonProperty("caller_functionname") + @ExcludeMissing + callerFunctionname: JsonField = JsonMissing.of(), + @JsonProperty("caller_lineno") + @ExcludeMissing + callerLineno: JsonField = JsonMissing.of(), + ) : this(callerFilename, callerFunctionname, callerLineno, mutableMapOf()) + /** * Name of the file in code where the project logs event was created * @@ -1050,22 +1087,15 @@ private constructor( @ExcludeMissing fun _callerLineno(): JsonField = callerLineno + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Context = apply { - if (validated) { - return@apply - } - - callerFilename() - callerFunctionname() - callerLineno() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1185,10 +1215,23 @@ private constructor( callerFilename, callerFunctionname, callerLineno, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Context = apply { + if (validated) { + return@apply + } + + callerFilename() + callerFunctionname() + callerLineno() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1214,17 +1257,17 @@ private constructor( * slice/dice later. The values in `metadata` can be any JSON-serializable type, but its keys * must be strings */ - @NoAutoDetect class Metadata - @JsonCreator private constructor( - @JsonProperty("model") - @ExcludeMissing - private val model: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val model: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("model") @ExcludeMissing model: JsonField = JsonMissing.of() + ) : this(model, mutableMapOf()) + /** * The model used for this example * @@ -1240,20 +1283,15 @@ private constructor( */ @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - model() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1314,7 +1352,18 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(model, additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(model, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + model() + validated = true } override fun equals(other: Any?): Boolean { @@ -1340,36 +1389,51 @@ private constructor( * project logs event. Use "start" and "end" to track the time span over which the project logs * event was produced */ - @NoAutoDetect class Metrics - @JsonCreator private constructor( - @JsonProperty("caller_filename") - @ExcludeMissing - private val callerFilename: JsonValue = JsonMissing.of(), - @JsonProperty("caller_functionname") - @ExcludeMissing - private val callerFunctionname: JsonValue = JsonMissing.of(), - @JsonProperty("caller_lineno") - @ExcludeMissing - private val callerLineno: JsonValue = JsonMissing.of(), - @JsonProperty("completion_tokens") - @ExcludeMissing - private val completionTokens: JsonField = JsonMissing.of(), - @JsonProperty("end") @ExcludeMissing private val end: JsonField = JsonMissing.of(), - @JsonProperty("prompt_tokens") - @ExcludeMissing - private val promptTokens: JsonField = JsonMissing.of(), - @JsonProperty("start") - @ExcludeMissing - private val start: JsonField = JsonMissing.of(), - @JsonProperty("tokens") - @ExcludeMissing - private val tokens: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val callerFilename: JsonValue, + private val callerFunctionname: JsonValue, + private val callerLineno: JsonValue, + private val completionTokens: JsonField, + private val end: JsonField, + private val promptTokens: JsonField, + private val start: JsonField, + private val tokens: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("caller_filename") + @ExcludeMissing + callerFilename: JsonValue = JsonMissing.of(), + @JsonProperty("caller_functionname") + @ExcludeMissing + callerFunctionname: JsonValue = JsonMissing.of(), + @JsonProperty("caller_lineno") + @ExcludeMissing + callerLineno: JsonValue = JsonMissing.of(), + @JsonProperty("completion_tokens") + @ExcludeMissing + completionTokens: JsonField = JsonMissing.of(), + @JsonProperty("end") @ExcludeMissing end: JsonField = JsonMissing.of(), + @JsonProperty("prompt_tokens") + @ExcludeMissing + promptTokens: JsonField = JsonMissing.of(), + @JsonProperty("start") @ExcludeMissing start: JsonField = JsonMissing.of(), + @JsonProperty("tokens") @ExcludeMissing tokens: JsonField = JsonMissing.of(), + ) : this( + callerFilename, + callerFunctionname, + callerLineno, + completionTokens, + end, + promptTokens, + start, + tokens, + mutableMapOf(), + ) + /** This metric is deprecated */ @JsonProperty("caller_filename") @ExcludeMissing @@ -1470,24 +1534,15 @@ private constructor( */ @JsonProperty("tokens") @ExcludeMissing fun _tokens(): JsonField = tokens + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Metrics = apply { - if (validated) { - return@apply - } - - completionTokens() - end() - promptTokens() - start() - tokens() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1701,10 +1756,25 @@ private constructor( promptTokens, start, tokens, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Metrics = apply { + if (validated) { + return@apply + } + + completionTokens() + end() + promptTokens() + start() + tokens() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1732,27 +1802,20 @@ private constructor( * whether the summarization was covering similar concepts or not. You can use these scores to * help you sort, filter, and compare logs. */ - @NoAutoDetect class Scores - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Scores = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1796,7 +1859,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Scores = Scores(additionalProperties.toImmutable()) + fun build(): Scores = Scores(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Scores = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectRetrieveParams.kt index 0e14857a..5fddd2dc 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectRetrieveParams.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers @@ -24,16 +23,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _pathParam(index: Int): String = - when (index) { - 0 -> projectId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - fun toBuilder() = Builder().from(this) companion object { @@ -50,7 +39,6 @@ private constructor( } /** A builder for [ProjectRetrieveParams]. */ - @NoAutoDetect class Builder internal constructor() { private var projectId: String? = null @@ -185,6 +173,16 @@ private constructor( ) } + fun _pathParam(index: Int): String = + when (index) { + 0 -> projectId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScore.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScore.kt index 023cbd6f..0a4d877a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScore.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScore.kt @@ -8,11 +8,8 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -26,44 +23,63 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull /** A project score is a user-configured score, which can be manually-labeled through the UI */ -@NoAutoDetect class ProjectScore -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing private val name: JsonField = JsonMissing.of(), - @JsonProperty("project_id") - @ExcludeMissing - private val projectId: JsonField = JsonMissing.of(), - @JsonProperty("score_type") - @ExcludeMissing - private val scoreType: JsonField = JsonMissing.of(), - @JsonProperty("user_id") - @ExcludeMissing - private val userId: JsonField = JsonMissing.of(), - @JsonProperty("categories") - @ExcludeMissing - private val categories: JsonField = JsonMissing.of(), - @JsonProperty("config") - @ExcludeMissing - private val config: JsonField = JsonMissing.of(), - @JsonProperty("created") - @ExcludeMissing - private val created: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("position") - @ExcludeMissing - private val position: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val name: JsonField, + private val projectId: JsonField, + private val scoreType: JsonField, + private val userId: JsonField, + private val categories: JsonField, + private val config: JsonField, + private val created: JsonField, + private val description: JsonField, + private val position: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("project_id") @ExcludeMissing projectId: JsonField = JsonMissing.of(), + @JsonProperty("score_type") + @ExcludeMissing + scoreType: JsonField = JsonMissing.of(), + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), + @JsonProperty("categories") + @ExcludeMissing + categories: JsonField = JsonMissing.of(), + @JsonProperty("config") + @ExcludeMissing + config: JsonField = JsonMissing.of(), + @JsonProperty("created") + @ExcludeMissing + created: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("position") @ExcludeMissing position: JsonField = JsonMissing.of(), + ) : this( + id, + name, + projectId, + scoreType, + userId, + categories, + config, + created, + description, + position, + mutableMapOf(), + ) + /** * Unique identifier for the project score * @@ -216,29 +232,15 @@ private constructor( */ @JsonProperty("position") @ExcludeMissing fun _position(): JsonField = position + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): ProjectScore = apply { - if (validated) { - return@apply - } - - id() - name() - projectId() - scoreType() - userId() - categories().ifPresent { it.validate() } - config().ifPresent { it.validate() } - created() - description() - position() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -475,10 +477,30 @@ private constructor( created, description, position, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): ProjectScore = apply { + if (validated) { + return@apply + } + + id() + name() + projectId() + scoreType() + userId() + categories().ifPresent { it.validate() } + config().ifPresent { it.validate() } + created() + description() + position() + validated = true + } + /** For categorical-type project scores, the list of all categories */ @JsonDeserialize(using = Categories.Deserializer::class) @JsonSerialize(using = Categories.Serializer::class) @@ -651,27 +673,20 @@ private constructor( } /** For weighted-type project scores, the weights of each score */ - @NoAutoDetect class Weighted - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Weighted = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -718,7 +733,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Weighted = Weighted(additionalProperties.toImmutable()) + fun build(): Weighted = Weighted(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Weighted = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCategory.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCategory.kt index b4504114..234a71f3 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCategory.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCategory.kt @@ -6,27 +6,29 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects /** For categorical-type project scores, defines a single category */ -@NoAutoDetect class ProjectScoreCategory -@JsonCreator private constructor( - @JsonProperty("name") @ExcludeMissing private val name: JsonField = JsonMissing.of(), - @JsonProperty("value") @ExcludeMissing private val value: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val name: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("value") @ExcludeMissing value: JsonField = JsonMissing.of(), + ) : this(name, value, mutableMapOf()) + /** * Name of the category * @@ -57,21 +59,15 @@ private constructor( */ @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): ProjectScoreCategory = apply { - if (validated) { - return@apply - } - - name() - value() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -161,10 +157,22 @@ private constructor( ProjectScoreCategory( checkRequired("name", name), checkRequired("value", value), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): ProjectScoreCategory = apply { + if (validated) { + return@apply + } + + name() + value() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreConfig.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreConfig.kt index 4ec3a301..6f32492f 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreConfig.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreConfig.kt @@ -6,34 +6,37 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class ProjectScoreConfig -@JsonCreator private constructor( - @JsonProperty("destination") - @ExcludeMissing - private val destination: JsonField = JsonMissing.of(), - @JsonProperty("multi_select") - @ExcludeMissing - private val multiSelect: JsonField = JsonMissing.of(), - @JsonProperty("online") - @ExcludeMissing - private val online: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val destination: JsonField, + private val multiSelect: JsonField, + private val online: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("destination") + @ExcludeMissing + destination: JsonField = JsonMissing.of(), + @JsonProperty("multi_select") + @ExcludeMissing + multiSelect: JsonField = JsonMissing.of(), + @JsonProperty("online") + @ExcludeMissing + online: JsonField = JsonMissing.of(), + ) : this(destination, multiSelect, online, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -77,22 +80,15 @@ private constructor( */ @JsonProperty("online") @ExcludeMissing fun _online(): JsonField = online + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): ProjectScoreConfig = apply { - if (validated) { - return@apply - } - - destination() - multiSelect() - online().ifPresent { it.validate() } - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -192,7 +188,25 @@ private constructor( * Further updates to this [Builder] will not mutate the returned instance. */ fun build(): ProjectScoreConfig = - ProjectScoreConfig(destination, multiSelect, online, additionalProperties.toImmutable()) + ProjectScoreConfig( + destination, + multiSelect, + online, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ProjectScoreConfig = apply { + if (validated) { + return@apply + } + + destination() + multiSelect() + online().ifPresent { it.validate() } + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParams.kt index 6b60c606..64a558f5 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParams.kt @@ -8,14 +8,11 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -28,6 +25,7 @@ import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -137,364 +135,248 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams + fun toBuilder() = Builder().from(this) - /** A project score is a user-configured score, which can be manually-labeled through the UI */ - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("project_id") - @ExcludeMissing - private val projectId: JsonField = JsonMissing.of(), - @JsonProperty("score_type") - @ExcludeMissing - private val scoreType: JsonField = JsonMissing.of(), - @JsonProperty("categories") - @ExcludeMissing - private val categories: JsonField = JsonMissing.of(), - @JsonProperty("config") - @ExcludeMissing - private val config: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + companion object { /** - * Name of the project score + * Returns a mutable builder for constructing an instance of [ProjectScoreCreateParams]. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + * The following fields are required: + * ```java + * .name() + * .projectId() + * .scoreType() + * ``` */ - fun name(): String = name.getRequired("name") + @JvmStatic fun builder() = Builder() + } - /** - * Unique identifier for the project that the project score belongs under - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun projectId(): String = projectId.getRequired("project_id") + /** A builder for [ProjectScoreCreateParams]. */ + class Builder internal constructor() { - /** - * The type of the configured score - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun scoreType(): ProjectScoreType = scoreType.getRequired("score_type") + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - /** - * For categorical-type project scores, the list of all categories - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun categories(): Optional = - Optional.ofNullable(categories.getNullable("categories")) + @JvmSynthetic + internal fun from(projectScoreCreateParams: ProjectScoreCreateParams) = apply { + body = projectScoreCreateParams.body.toBuilder() + additionalHeaders = projectScoreCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = projectScoreCreateParams.additionalQueryParams.toBuilder() + } - /** - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun config(): Optional = - Optional.ofNullable(config.getNullable("config")) + /** Name of the project score */ + fun name(name: String) = apply { body.name(name) } /** - * Textual description of the project score + * Sets [Builder.name] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun name(name: JsonField) = apply { body.name(name) } - /** - * Returns the raw JSON value of [name]. - * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + /** Unique identifier for the project that the project score belongs under */ + fun projectId(projectId: String) = apply { body.projectId(projectId) } /** - * Returns the raw JSON value of [projectId]. + * Sets [Builder.projectId] to an arbitrary JSON value. * - * Unlike [projectId], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.projectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("project_id") @ExcludeMissing fun _projectId(): JsonField = projectId + fun projectId(projectId: JsonField) = apply { body.projectId(projectId) } - /** - * Returns the raw JSON value of [scoreType]. - * - * Unlike [scoreType], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("score_type") - @ExcludeMissing - fun _scoreType(): JsonField = scoreType + /** The type of the configured score */ + fun scoreType(scoreType: ProjectScoreType) = apply { body.scoreType(scoreType) } /** - * Returns the raw JSON value of [categories]. + * Sets [Builder.scoreType] to an arbitrary JSON value. * - * Unlike [categories], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.scoreType] with a well-typed [ProjectScoreType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("categories") - @ExcludeMissing - fun _categories(): JsonField = categories + fun scoreType(scoreType: JsonField) = apply { body.scoreType(scoreType) } - /** - * Returns the raw JSON value of [config]. - * - * Unlike [config], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("config") - @ExcludeMissing - fun _config(): JsonField = config + /** For categorical-type project scores, the list of all categories */ + fun categories(categories: Categories?) = apply { body.categories(categories) } + + /** Alias for calling [Builder.categories] with `categories.orElse(null)`. */ + fun categories(categories: Optional) = categories(categories.getOrNull()) /** - * Returns the raw JSON value of [description]. + * Sets [Builder.categories] to an arbitrary JSON value. * - * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.categories] with a well-typed [Categories] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("description") - @ExcludeMissing - fun _description(): JsonField = description - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } + fun categories(categories: JsonField) = apply { body.categories(categories) } - name() - projectId() - scoreType() - categories().ifPresent { it.validate() } - config().ifPresent { it.validate() } - description() - validated = true + /** Alias for calling [categories] with `Categories.ofCategorical(categorical)`. */ + fun categoriesOfCategorical(categorical: List) = apply { + body.categoriesOfCategorical(categorical) } - fun toBuilder() = Builder().from(this) - - companion object { + /** Alias for calling [categories] with `Categories.ofWeighted(weighted)`. */ + fun categories(weighted: Categories.Weighted) = apply { body.categories(weighted) } - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .name() - * .projectId() - * .scoreType() - * ``` - */ - @JvmStatic fun builder() = Builder() - } + /** Alias for calling [categories] with `Categories.ofMinimum(minimum)`. */ + fun categoriesOfMinimum(minimum: List) = apply { body.categoriesOfMinimum(minimum) } - /** A builder for [Body]. */ - class Builder internal constructor() { + fun config(config: ProjectScoreConfig?) = apply { body.config(config) } - private var name: JsonField? = null - private var projectId: JsonField? = null - private var scoreType: JsonField? = null - private var categories: JsonField = JsonMissing.of() - private var config: JsonField = JsonMissing.of() - private var description: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + /** Alias for calling [Builder.config] with `config.orElse(null)`. */ + fun config(config: Optional) = config(config.getOrNull()) - @JvmSynthetic - internal fun from(body: Body) = apply { - name = body.name - projectId = body.projectId - scoreType = body.scoreType - categories = body.categories - config = body.config - description = body.description - additionalProperties = body.additionalProperties.toMutableMap() - } + /** + * Sets [Builder.config] to an arbitrary JSON value. + * + * You should usually call [Builder.config] with a well-typed [ProjectScoreConfig] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun config(config: JsonField) = apply { body.config(config) } - /** Name of the project score */ - fun name(name: String) = name(JsonField.of(name)) + /** Textual description of the project score */ + fun description(description: String?) = apply { body.description(description) } - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) - /** Unique identifier for the project that the project score belongs under */ - fun projectId(projectId: String) = projectId(JsonField.of(projectId)) + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun description(description: JsonField) = apply { body.description(description) } - /** - * Sets [Builder.projectId] to an arbitrary JSON value. - * - * You should usually call [Builder.projectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun projectId(projectId: JsonField) = apply { this.projectId = projectId } + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } - /** The type of the configured score */ - fun scoreType(scoreType: ProjectScoreType) = scoreType(JsonField.of(scoreType)) + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } - /** - * Sets [Builder.scoreType] to an arbitrary JSON value. - * - * You should usually call [Builder.scoreType] with a well-typed [ProjectScoreType] - * value instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun scoreType(scoreType: JsonField) = apply { - this.scoreType = scoreType + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) } - /** For categorical-type project scores, the list of all categories */ - fun categories(categories: Categories?) = categories(JsonField.ofNullable(categories)) + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - /** Alias for calling [Builder.categories] with `categories.orElse(null)`. */ - fun categories(categories: Optional) = categories(categories.getOrNull()) + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } - /** - * Sets [Builder.categories] to an arbitrary JSON value. - * - * You should usually call [Builder.categories] with a well-typed [Categories] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun categories(categories: JsonField) = apply { - this.categories = categories - } + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** Alias for calling [categories] with `Categories.ofCategorical(categorical)`. */ - fun categoriesOfCategorical(categorical: List) = - categories(Categories.ofCategorical(categorical)) + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** Alias for calling [categories] with `Categories.ofWeighted(weighted)`. */ - fun categories(weighted: Categories.Weighted) = - categories(Categories.ofWeighted(weighted)) + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } - /** Alias for calling [categories] with `Categories.ofMinimum(minimum)`. */ - fun categoriesOfMinimum(minimum: List) = - categories(Categories.ofMinimum(minimum)) + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - fun config(config: ProjectScoreConfig?) = config(JsonField.ofNullable(config)) + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** Alias for calling [Builder.config] with `config.orElse(null)`. */ - fun config(config: Optional) = config(config.getOrNull()) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** - * Sets [Builder.config] to an arbitrary JSON value. - * - * You should usually call [Builder.config] with a well-typed [ProjectScoreConfig] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun config(config: JsonField) = apply { this.config = config } + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - /** Textual description of the project score */ - fun description(description: String?) = description(JsonField.ofNullable(description)) + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun description(description: JsonField) = apply { - this.description = description - } + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * .projectId() - * .scoreType() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("name", name), - checkRequired("projectId", projectId), - checkRequired("scoreType", scoreType), - categories, - config, - description, - additionalProperties.toImmutable(), - ) + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - return /* spotless:off */ other is Body && name == other.name && projectId == other.projectId && scoreType == other.scoreType && categories == other.categories && config == other.config && description == other.description && additionalProperties == other.additionalProperties /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, projectId, scoreType, categories, config, description, additionalProperties) } - /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } - override fun hashCode(): Int = hashCode + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - override fun toString() = - "Body{name=$name, projectId=$projectId, scoreType=$scoreType, categories=$categories, config=$config, description=$description, additionalProperties=$additionalProperties}" - } + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - fun toBuilder() = Builder().from(this) + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - companion object { + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } /** - * Returns a mutable builder for constructing an instance of [ProjectScoreCreateParams]. + * Returns an immutable instance of [ProjectScoreCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java @@ -502,252 +384,378 @@ private constructor( * .projectId() * .scoreType() * ``` + * + * @throws IllegalStateException if any required field is unset. */ - @JvmStatic fun builder() = Builder() + fun build(): ProjectScoreCreateParams = + ProjectScoreCreateParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) } - /** A builder for [ProjectScoreCreateParams]. */ - @NoAutoDetect - class Builder internal constructor() { + @JvmSynthetic internal fun _body(): Body = body - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun from(projectScoreCreateParams: ProjectScoreCreateParams) = apply { - body = projectScoreCreateParams.body.toBuilder() - additionalHeaders = projectScoreCreateParams.additionalHeaders.toBuilder() - additionalQueryParams = projectScoreCreateParams.additionalQueryParams.toBuilder() - } + override fun _queryParams(): QueryParams = additionalQueryParams - /** Name of the project score */ - fun name(name: String) = apply { body.name(name) } + /** A project score is a user-configured score, which can be manually-labeled through the UI */ + class Body + private constructor( + private val name: JsonField, + private val projectId: JsonField, + private val scoreType: JsonField, + private val categories: JsonField, + private val config: JsonField, + private val description: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("score_type") + @ExcludeMissing + scoreType: JsonField = JsonMissing.of(), + @JsonProperty("categories") + @ExcludeMissing + categories: JsonField = JsonMissing.of(), + @JsonProperty("config") + @ExcludeMissing + config: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + ) : this(name, projectId, scoreType, categories, config, description, mutableMapOf()) /** - * Sets [Builder.name] to an arbitrary JSON value. + * Name of the project score * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun name(name: JsonField) = apply { body.name(name) } - - /** Unique identifier for the project that the project score belongs under */ - fun projectId(projectId: String) = apply { body.projectId(projectId) } + fun name(): String = name.getRequired("name") /** - * Sets [Builder.projectId] to an arbitrary JSON value. + * Unique identifier for the project that the project score belongs under * - * You should usually call [Builder.projectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun projectId(projectId: JsonField) = apply { body.projectId(projectId) } - - /** The type of the configured score */ - fun scoreType(scoreType: ProjectScoreType) = apply { body.scoreType(scoreType) } + fun projectId(): String = projectId.getRequired("project_id") /** - * Sets [Builder.scoreType] to an arbitrary JSON value. + * The type of the configured score * - * You should usually call [Builder.scoreType] with a well-typed [ProjectScoreType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun scoreType(scoreType: JsonField) = apply { body.scoreType(scoreType) } - - /** For categorical-type project scores, the list of all categories */ - fun categories(categories: Categories?) = apply { body.categories(categories) } - - /** Alias for calling [Builder.categories] with `categories.orElse(null)`. */ - fun categories(categories: Optional) = categories(categories.getOrNull()) + fun scoreType(): ProjectScoreType = scoreType.getRequired("score_type") /** - * Sets [Builder.categories] to an arbitrary JSON value. + * For categorical-type project scores, the list of all categories * - * You should usually call [Builder.categories] with a well-typed [Categories] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun categories(categories: JsonField) = apply { body.categories(categories) } - - /** Alias for calling [categories] with `Categories.ofCategorical(categorical)`. */ - fun categoriesOfCategorical(categorical: List) = apply { - body.categoriesOfCategorical(categorical) - } + fun categories(): Optional = + Optional.ofNullable(categories.getNullable("categories")) - /** Alias for calling [categories] with `Categories.ofWeighted(weighted)`. */ - fun categories(weighted: Categories.Weighted) = apply { body.categories(weighted) } + /** + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun config(): Optional = + Optional.ofNullable(config.getNullable("config")) - /** Alias for calling [categories] with `Categories.ofMinimum(minimum)`. */ - fun categoriesOfMinimum(minimum: List) = apply { body.categoriesOfMinimum(minimum) } + /** + * Textual description of the project score + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun description(): Optional = + Optional.ofNullable(description.getNullable("description")) - fun config(config: ProjectScoreConfig?) = apply { body.config(config) } + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - /** Alias for calling [Builder.config] with `config.orElse(null)`. */ - fun config(config: Optional) = config(config.getOrNull()) + /** + * Returns the raw JSON value of [projectId]. + * + * Unlike [projectId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("project_id") @ExcludeMissing fun _projectId(): JsonField = projectId /** - * Sets [Builder.config] to an arbitrary JSON value. + * Returns the raw JSON value of [scoreType]. * - * You should usually call [Builder.config] with a well-typed [ProjectScoreConfig] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * Unlike [scoreType], this method doesn't throw if the JSON field has an unexpected type. */ - fun config(config: JsonField) = apply { body.config(config) } + @JsonProperty("score_type") + @ExcludeMissing + fun _scoreType(): JsonField = scoreType - /** Textual description of the project score */ - fun description(description: String?) = apply { body.description(description) } + /** + * Returns the raw JSON value of [categories]. + * + * Unlike [categories], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("categories") + @ExcludeMissing + fun _categories(): JsonField = categories - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) + /** + * Returns the raw JSON value of [config]. + * + * Unlike [config], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("config") + @ExcludeMissing + fun _config(): JsonField = config /** - * Sets [Builder.description] to an arbitrary JSON value. + * Returns the raw JSON value of [description]. * - * You should usually call [Builder.description] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. */ - fun description(description: JsonField) = apply { body.description(description) } + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .name() + * .projectId() + * .scoreType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var name: JsonField? = null + private var projectId: JsonField? = null + private var scoreType: JsonField? = null + private var categories: JsonField = JsonMissing.of() + private var config: JsonField = JsonMissing.of() + private var description: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + name = body.name + projectId = body.projectId + scoreType = body.scoreType + categories = body.categories + config = body.config + description = body.description + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** Name of the project score */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** Unique identifier for the project that the project score belongs under */ + fun projectId(projectId: String) = projectId(JsonField.of(projectId)) - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) - } + /** + * Sets [Builder.projectId] to an arbitrary JSON value. + * + * You should usually call [Builder.projectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun projectId(projectId: JsonField) = apply { this.projectId = projectId } - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } + /** The type of the configured score */ + fun scoreType(scoreType: ProjectScoreType) = scoreType(JsonField.of(scoreType)) - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) + /** + * Sets [Builder.scoreType] to an arbitrary JSON value. + * + * You should usually call [Builder.scoreType] with a well-typed [ProjectScoreType] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun scoreType(scoreType: JsonField) = apply { + this.scoreType = scoreType } - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + /** For categorical-type project scores, the list of all categories */ + fun categories(categories: Categories?) = categories(JsonField.ofNullable(categories)) - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } + /** Alias for calling [Builder.categories] with `categories.orElse(null)`. */ + fun categories(categories: Optional) = categories(categories.getOrNull()) - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * Sets [Builder.categories] to an arbitrary JSON value. + * + * You should usually call [Builder.categories] with a well-typed [Categories] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun categories(categories: JsonField) = apply { + this.categories = categories + } - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** Alias for calling [categories] with `Categories.ofCategorical(categorical)`. */ + fun categoriesOfCategorical(categorical: List) = + categories(Categories.ofCategorical(categorical)) - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } + /** Alias for calling [categories] with `Categories.ofWeighted(weighted)`. */ + fun categories(weighted: Categories.Weighted) = + categories(Categories.ofWeighted(weighted)) - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } + /** Alias for calling [categories] with `Categories.ofMinimum(minimum)`. */ + fun categoriesOfMinimum(minimum: List) = + categories(Categories.ofMinimum(minimum)) - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + fun config(config: ProjectScoreConfig?) = config(JsonField.ofNullable(config)) - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** Alias for calling [Builder.config] with `config.orElse(null)`. */ + fun config(config: Optional) = config(config.getOrNull()) - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } + /** + * Sets [Builder.config] to an arbitrary JSON value. + * + * You should usually call [Builder.config] with a well-typed [ProjectScoreConfig] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun config(config: JsonField) = apply { this.config = config } - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } + /** Textual description of the project score */ + fun description(description: String?) = description(JsonField.ofNullable(description)) - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * .projectId() + * .scoreType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("name", name), + checkRequired("projectId", projectId), + checkRequired("scoreType", scoreType), + categories, + config, + description, + additionalProperties.toMutableMap(), + ) } - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } + private var validated: Boolean = false - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + fun validate(): Body = apply { + if (validated) { + return@apply } - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) + name() + projectId() + scoreType() + categories().ifPresent { it.validate() } + config().ifPresent { it.validate() } + description() + validated = true } - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + return /* spotless:off */ other is Body && name == other.name && projectId == other.projectId && scoreType == other.scoreType && categories == other.categories && config == other.config && description == other.description && additionalProperties == other.additionalProperties /* spotless:on */ } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) - } - - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(name, projectId, scoreType, categories, config, description, additionalProperties) } + /* spotless:on */ - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) - } + override fun hashCode(): Int = hashCode - /** - * Returns an immutable instance of [ProjectScoreCreateParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * .projectId() - * .scoreType() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ProjectScoreCreateParams = - ProjectScoreCreateParams( - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + override fun toString() = + "Body{name=$name, projectId=$projectId, scoreType=$scoreType, categories=$categories, config=$config, description=$description, additionalProperties=$additionalProperties}" } /** For categorical-type project scores, the list of all categories */ @@ -922,27 +930,20 @@ private constructor( } /** For weighted-type project scores, the weights of each score */ - @NoAutoDetect class Weighted - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Weighted = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -989,7 +990,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Weighted = Weighted(additionalProperties.toImmutable()) + fun build(): Weighted = Weighted(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Weighted = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreDeleteParams.kt index 03afc845..4150f67f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreDeleteParams.kt @@ -2,13 +2,15 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.toImmutable +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import java.util.Collections import java.util.Objects import java.util.Optional @@ -18,7 +20,7 @@ private constructor( private val projectScoreId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: Map, + private val additionalBodyProperties: MutableMap, ) : Params { /** ProjectScore id */ @@ -28,21 +30,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _additionalBodyProperties(): Map = additionalBodyProperties - - @JvmSynthetic - internal fun _body(): Optional> = - Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - - fun _pathParam(index: Int): String = - when (index) { - 0 -> projectScoreId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders + @JsonAnySetter + private fun putAdditionalBodyProperty(key: String, value: JsonValue) { + additionalBodyProperties.put(key, value) + } - override fun _queryParams(): QueryParams = additionalQueryParams + @JsonAnyGetter + @ExcludeMissing + fun _additionalBodyProperties(): Map = + Collections.unmodifiableMap(additionalBodyProperties) fun toBuilder() = Builder().from(this) @@ -60,7 +56,6 @@ private constructor( } /** A builder for [ProjectScoreDeleteParams]. */ - @NoAutoDetect class Builder internal constructor() { private var projectScoreId: String? = null @@ -217,10 +212,24 @@ private constructor( checkRequired("projectScoreId", projectScoreId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toImmutable(), + additionalBodyProperties.toMutableMap(), ) } + @JvmSynthetic + internal fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> projectScoreId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt index 904e8477..c997e41d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.blocking.ProjectScoreService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -90,24 +88,30 @@ private constructor( ) = ProjectScoreListPage(projectScoresService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") - private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -165,7 +169,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt index 0f5c5540..1109ba6c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.async.ProjectScoreServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -92,24 +90,30 @@ private constructor( ) = ProjectScoreListPageAsync(projectScoresService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") - private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -170,7 +174,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListParams.kt index 14f151cd..e4d1432f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListParams.kt @@ -5,7 +5,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.BaseDeserializer import com.braintrustdata.api.core.BaseSerializer import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers @@ -87,46 +86,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = - QueryParams.builder() - .apply { - endingBefore?.let { put("ending_before", it) } - ids?.accept( - object : Ids.Visitor { - override fun visitString(string: String) { - put("ids", string) - } - - override fun visitStrings(strings: List) { - put("ids", strings.joinToString(",")) - } - } - ) - limit?.let { put("limit", it.toString()) } - orgName?.let { put("org_name", it) } - projectId?.let { put("project_id", it) } - projectName?.let { put("project_name", it) } - projectScoreName?.let { put("project_score_name", it) } - scoreType?.accept( - object : ScoreType.Visitor { - override fun visitProject(project: ProjectScoreType) { - put("score_type", project.toString()) - } - - override fun visitProjectScoreTypes( - projectScoreTypes: List - ) { - put("score_type", projectScoreTypes.joinToString(",") { it.toString() }) - } - } - ) - startingAfter?.let { put("starting_after", it) } - putAll(additionalQueryParams) - } - .build() - fun toBuilder() = Builder().from(this) companion object { @@ -138,7 +97,6 @@ private constructor( } /** A builder for [ProjectScoreListParams]. */ - @NoAutoDetect class Builder internal constructor() { private var endingBefore: String? = null @@ -382,6 +340,46 @@ private constructor( ) } + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + endingBefore?.let { put("ending_before", it) } + ids?.accept( + object : Ids.Visitor { + override fun visitString(string: String) { + put("ids", string) + } + + override fun visitStrings(strings: List) { + put("ids", strings.joinToString(",")) + } + } + ) + limit?.let { put("limit", it.toString()) } + orgName?.let { put("org_name", it) } + projectId?.let { put("project_id", it) } + projectName?.let { put("project_name", it) } + projectScoreName?.let { put("project_score_name", it) } + scoreType?.accept( + object : ScoreType.Visitor { + override fun visitProject(project: ProjectScoreType) { + put("score_type", project.toString()) + } + + override fun visitProjectScoreTypes( + projectScoreTypes: List + ) { + put("score_type", projectScoreTypes.joinToString(",") { it.toString() }) + } + } + ) + startingAfter?.let { put("starting_after", it) } + putAll(additionalQueryParams) + } + .build() + /** * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParams.kt index 439137c0..e5d8d410 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParams.kt @@ -8,14 +8,11 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -28,6 +25,7 @@ import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -138,364 +136,248 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams + fun toBuilder() = Builder().from(this) - /** A project score is a user-configured score, which can be manually-labeled through the UI */ - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("project_id") - @ExcludeMissing - private val projectId: JsonField = JsonMissing.of(), - @JsonProperty("score_type") - @ExcludeMissing - private val scoreType: JsonField = JsonMissing.of(), - @JsonProperty("categories") - @ExcludeMissing - private val categories: JsonField = JsonMissing.of(), - @JsonProperty("config") - @ExcludeMissing - private val config: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + companion object { /** - * Name of the project score + * Returns a mutable builder for constructing an instance of [ProjectScoreReplaceParams]. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + * The following fields are required: + * ```java + * .name() + * .projectId() + * .scoreType() + * ``` */ - fun name(): String = name.getRequired("name") + @JvmStatic fun builder() = Builder() + } - /** - * Unique identifier for the project that the project score belongs under - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun projectId(): String = projectId.getRequired("project_id") + /** A builder for [ProjectScoreReplaceParams]. */ + class Builder internal constructor() { - /** - * The type of the configured score - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun scoreType(): ProjectScoreType = scoreType.getRequired("score_type") + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - /** - * For categorical-type project scores, the list of all categories - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun categories(): Optional = - Optional.ofNullable(categories.getNullable("categories")) + @JvmSynthetic + internal fun from(projectScoreReplaceParams: ProjectScoreReplaceParams) = apply { + body = projectScoreReplaceParams.body.toBuilder() + additionalHeaders = projectScoreReplaceParams.additionalHeaders.toBuilder() + additionalQueryParams = projectScoreReplaceParams.additionalQueryParams.toBuilder() + } - /** - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun config(): Optional = - Optional.ofNullable(config.getNullable("config")) + /** Name of the project score */ + fun name(name: String) = apply { body.name(name) } /** - * Textual description of the project score + * Sets [Builder.name] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun name(name: JsonField) = apply { body.name(name) } - /** - * Returns the raw JSON value of [name]. - * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + /** Unique identifier for the project that the project score belongs under */ + fun projectId(projectId: String) = apply { body.projectId(projectId) } /** - * Returns the raw JSON value of [projectId]. + * Sets [Builder.projectId] to an arbitrary JSON value. * - * Unlike [projectId], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.projectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("project_id") @ExcludeMissing fun _projectId(): JsonField = projectId + fun projectId(projectId: JsonField) = apply { body.projectId(projectId) } - /** - * Returns the raw JSON value of [scoreType]. - * - * Unlike [scoreType], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("score_type") - @ExcludeMissing - fun _scoreType(): JsonField = scoreType + /** The type of the configured score */ + fun scoreType(scoreType: ProjectScoreType) = apply { body.scoreType(scoreType) } /** - * Returns the raw JSON value of [categories]. + * Sets [Builder.scoreType] to an arbitrary JSON value. * - * Unlike [categories], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.scoreType] with a well-typed [ProjectScoreType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("categories") - @ExcludeMissing - fun _categories(): JsonField = categories + fun scoreType(scoreType: JsonField) = apply { body.scoreType(scoreType) } - /** - * Returns the raw JSON value of [config]. - * - * Unlike [config], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("config") - @ExcludeMissing - fun _config(): JsonField = config + /** For categorical-type project scores, the list of all categories */ + fun categories(categories: Categories?) = apply { body.categories(categories) } + + /** Alias for calling [Builder.categories] with `categories.orElse(null)`. */ + fun categories(categories: Optional) = categories(categories.getOrNull()) /** - * Returns the raw JSON value of [description]. + * Sets [Builder.categories] to an arbitrary JSON value. * - * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.categories] with a well-typed [Categories] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("description") - @ExcludeMissing - fun _description(): JsonField = description - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } + fun categories(categories: JsonField) = apply { body.categories(categories) } - name() - projectId() - scoreType() - categories().ifPresent { it.validate() } - config().ifPresent { it.validate() } - description() - validated = true + /** Alias for calling [categories] with `Categories.ofCategorical(categorical)`. */ + fun categoriesOfCategorical(categorical: List) = apply { + body.categoriesOfCategorical(categorical) } - fun toBuilder() = Builder().from(this) - - companion object { + /** Alias for calling [categories] with `Categories.ofWeighted(weighted)`. */ + fun categories(weighted: Categories.Weighted) = apply { body.categories(weighted) } - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .name() - * .projectId() - * .scoreType() - * ``` - */ - @JvmStatic fun builder() = Builder() - } + /** Alias for calling [categories] with `Categories.ofMinimum(minimum)`. */ + fun categoriesOfMinimum(minimum: List) = apply { body.categoriesOfMinimum(minimum) } - /** A builder for [Body]. */ - class Builder internal constructor() { + fun config(config: ProjectScoreConfig?) = apply { body.config(config) } - private var name: JsonField? = null - private var projectId: JsonField? = null - private var scoreType: JsonField? = null - private var categories: JsonField = JsonMissing.of() - private var config: JsonField = JsonMissing.of() - private var description: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + /** Alias for calling [Builder.config] with `config.orElse(null)`. */ + fun config(config: Optional) = config(config.getOrNull()) - @JvmSynthetic - internal fun from(body: Body) = apply { - name = body.name - projectId = body.projectId - scoreType = body.scoreType - categories = body.categories - config = body.config - description = body.description - additionalProperties = body.additionalProperties.toMutableMap() - } + /** + * Sets [Builder.config] to an arbitrary JSON value. + * + * You should usually call [Builder.config] with a well-typed [ProjectScoreConfig] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun config(config: JsonField) = apply { body.config(config) } - /** Name of the project score */ - fun name(name: String) = name(JsonField.of(name)) + /** Textual description of the project score */ + fun description(description: String?) = apply { body.description(description) } - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) - /** Unique identifier for the project that the project score belongs under */ - fun projectId(projectId: String) = projectId(JsonField.of(projectId)) + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun description(description: JsonField) = apply { body.description(description) } - /** - * Sets [Builder.projectId] to an arbitrary JSON value. - * - * You should usually call [Builder.projectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun projectId(projectId: JsonField) = apply { this.projectId = projectId } + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } - /** The type of the configured score */ - fun scoreType(scoreType: ProjectScoreType) = scoreType(JsonField.of(scoreType)) + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } - /** - * Sets [Builder.scoreType] to an arbitrary JSON value. - * - * You should usually call [Builder.scoreType] with a well-typed [ProjectScoreType] - * value instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun scoreType(scoreType: JsonField) = apply { - this.scoreType = scoreType + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) } - /** For categorical-type project scores, the list of all categories */ - fun categories(categories: Categories?) = categories(JsonField.ofNullable(categories)) + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - /** Alias for calling [Builder.categories] with `categories.orElse(null)`. */ - fun categories(categories: Optional) = categories(categories.getOrNull()) + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } - /** - * Sets [Builder.categories] to an arbitrary JSON value. - * - * You should usually call [Builder.categories] with a well-typed [Categories] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun categories(categories: JsonField) = apply { - this.categories = categories - } + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** Alias for calling [categories] with `Categories.ofCategorical(categorical)`. */ - fun categoriesOfCategorical(categorical: List) = - categories(Categories.ofCategorical(categorical)) + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** Alias for calling [categories] with `Categories.ofWeighted(weighted)`. */ - fun categories(weighted: Categories.Weighted) = - categories(Categories.ofWeighted(weighted)) + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } - /** Alias for calling [categories] with `Categories.ofMinimum(minimum)`. */ - fun categoriesOfMinimum(minimum: List) = - categories(Categories.ofMinimum(minimum)) + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - fun config(config: ProjectScoreConfig?) = config(JsonField.ofNullable(config)) + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** Alias for calling [Builder.config] with `config.orElse(null)`. */ - fun config(config: Optional) = config(config.getOrNull()) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** - * Sets [Builder.config] to an arbitrary JSON value. - * - * You should usually call [Builder.config] with a well-typed [ProjectScoreConfig] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun config(config: JsonField) = apply { this.config = config } + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - /** Textual description of the project score */ - fun description(description: String?) = description(JsonField.ofNullable(description)) + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun description(description: JsonField) = apply { - this.description = description - } + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * .projectId() - * .scoreType() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("name", name), - checkRequired("projectId", projectId), - checkRequired("scoreType", scoreType), - categories, - config, - description, - additionalProperties.toImmutable(), - ) + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - return /* spotless:off */ other is Body && name == other.name && projectId == other.projectId && scoreType == other.scoreType && categories == other.categories && config == other.config && description == other.description && additionalProperties == other.additionalProperties /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, projectId, scoreType, categories, config, description, additionalProperties) } - /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } - override fun hashCode(): Int = hashCode + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - override fun toString() = - "Body{name=$name, projectId=$projectId, scoreType=$scoreType, categories=$categories, config=$config, description=$description, additionalProperties=$additionalProperties}" - } + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - fun toBuilder() = Builder().from(this) + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - companion object { + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } /** - * Returns a mutable builder for constructing an instance of [ProjectScoreReplaceParams]. + * Returns an immutable instance of [ProjectScoreReplaceParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java @@ -503,252 +385,378 @@ private constructor( * .projectId() * .scoreType() * ``` + * + * @throws IllegalStateException if any required field is unset. */ - @JvmStatic fun builder() = Builder() + fun build(): ProjectScoreReplaceParams = + ProjectScoreReplaceParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) } - /** A builder for [ProjectScoreReplaceParams]. */ - @NoAutoDetect - class Builder internal constructor() { + @JvmSynthetic internal fun _body(): Body = body - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun from(projectScoreReplaceParams: ProjectScoreReplaceParams) = apply { - body = projectScoreReplaceParams.body.toBuilder() - additionalHeaders = projectScoreReplaceParams.additionalHeaders.toBuilder() - additionalQueryParams = projectScoreReplaceParams.additionalQueryParams.toBuilder() - } + override fun _queryParams(): QueryParams = additionalQueryParams - /** Name of the project score */ - fun name(name: String) = apply { body.name(name) } + /** A project score is a user-configured score, which can be manually-labeled through the UI */ + class Body + private constructor( + private val name: JsonField, + private val projectId: JsonField, + private val scoreType: JsonField, + private val categories: JsonField, + private val config: JsonField, + private val description: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("score_type") + @ExcludeMissing + scoreType: JsonField = JsonMissing.of(), + @JsonProperty("categories") + @ExcludeMissing + categories: JsonField = JsonMissing.of(), + @JsonProperty("config") + @ExcludeMissing + config: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + ) : this(name, projectId, scoreType, categories, config, description, mutableMapOf()) /** - * Sets [Builder.name] to an arbitrary JSON value. + * Name of the project score * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun name(name: JsonField) = apply { body.name(name) } - - /** Unique identifier for the project that the project score belongs under */ - fun projectId(projectId: String) = apply { body.projectId(projectId) } + fun name(): String = name.getRequired("name") /** - * Sets [Builder.projectId] to an arbitrary JSON value. + * Unique identifier for the project that the project score belongs under * - * You should usually call [Builder.projectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun projectId(projectId: JsonField) = apply { body.projectId(projectId) } - - /** The type of the configured score */ - fun scoreType(scoreType: ProjectScoreType) = apply { body.scoreType(scoreType) } + fun projectId(): String = projectId.getRequired("project_id") /** - * Sets [Builder.scoreType] to an arbitrary JSON value. + * The type of the configured score * - * You should usually call [Builder.scoreType] with a well-typed [ProjectScoreType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun scoreType(scoreType: JsonField) = apply { body.scoreType(scoreType) } - - /** For categorical-type project scores, the list of all categories */ - fun categories(categories: Categories?) = apply { body.categories(categories) } - - /** Alias for calling [Builder.categories] with `categories.orElse(null)`. */ - fun categories(categories: Optional) = categories(categories.getOrNull()) + fun scoreType(): ProjectScoreType = scoreType.getRequired("score_type") /** - * Sets [Builder.categories] to an arbitrary JSON value. + * For categorical-type project scores, the list of all categories * - * You should usually call [Builder.categories] with a well-typed [Categories] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun categories(categories: JsonField) = apply { body.categories(categories) } - - /** Alias for calling [categories] with `Categories.ofCategorical(categorical)`. */ - fun categoriesOfCategorical(categorical: List) = apply { - body.categoriesOfCategorical(categorical) - } + fun categories(): Optional = + Optional.ofNullable(categories.getNullable("categories")) - /** Alias for calling [categories] with `Categories.ofWeighted(weighted)`. */ - fun categories(weighted: Categories.Weighted) = apply { body.categories(weighted) } + /** + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun config(): Optional = + Optional.ofNullable(config.getNullable("config")) - /** Alias for calling [categories] with `Categories.ofMinimum(minimum)`. */ - fun categoriesOfMinimum(minimum: List) = apply { body.categoriesOfMinimum(minimum) } + /** + * Textual description of the project score + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun description(): Optional = + Optional.ofNullable(description.getNullable("description")) - fun config(config: ProjectScoreConfig?) = apply { body.config(config) } + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - /** Alias for calling [Builder.config] with `config.orElse(null)`. */ - fun config(config: Optional) = config(config.getOrNull()) + /** + * Returns the raw JSON value of [projectId]. + * + * Unlike [projectId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("project_id") @ExcludeMissing fun _projectId(): JsonField = projectId /** - * Sets [Builder.config] to an arbitrary JSON value. + * Returns the raw JSON value of [scoreType]. * - * You should usually call [Builder.config] with a well-typed [ProjectScoreConfig] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * Unlike [scoreType], this method doesn't throw if the JSON field has an unexpected type. */ - fun config(config: JsonField) = apply { body.config(config) } + @JsonProperty("score_type") + @ExcludeMissing + fun _scoreType(): JsonField = scoreType - /** Textual description of the project score */ - fun description(description: String?) = apply { body.description(description) } + /** + * Returns the raw JSON value of [categories]. + * + * Unlike [categories], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("categories") + @ExcludeMissing + fun _categories(): JsonField = categories - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) + /** + * Returns the raw JSON value of [config]. + * + * Unlike [config], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("config") + @ExcludeMissing + fun _config(): JsonField = config /** - * Sets [Builder.description] to an arbitrary JSON value. + * Returns the raw JSON value of [description]. * - * You should usually call [Builder.description] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. */ - fun description(description: JsonField) = apply { body.description(description) } + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .name() + * .projectId() + * .scoreType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var name: JsonField? = null + private var projectId: JsonField? = null + private var scoreType: JsonField? = null + private var categories: JsonField = JsonMissing.of() + private var config: JsonField = JsonMissing.of() + private var description: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + name = body.name + projectId = body.projectId + scoreType = body.scoreType + categories = body.categories + config = body.config + description = body.description + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** Name of the project score */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** Unique identifier for the project that the project score belongs under */ + fun projectId(projectId: String) = projectId(JsonField.of(projectId)) - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) - } + /** + * Sets [Builder.projectId] to an arbitrary JSON value. + * + * You should usually call [Builder.projectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun projectId(projectId: JsonField) = apply { this.projectId = projectId } - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } + /** The type of the configured score */ + fun scoreType(scoreType: ProjectScoreType) = scoreType(JsonField.of(scoreType)) - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) + /** + * Sets [Builder.scoreType] to an arbitrary JSON value. + * + * You should usually call [Builder.scoreType] with a well-typed [ProjectScoreType] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun scoreType(scoreType: JsonField) = apply { + this.scoreType = scoreType } - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + /** For categorical-type project scores, the list of all categories */ + fun categories(categories: Categories?) = categories(JsonField.ofNullable(categories)) - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } + /** Alias for calling [Builder.categories] with `categories.orElse(null)`. */ + fun categories(categories: Optional) = categories(categories.getOrNull()) - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * Sets [Builder.categories] to an arbitrary JSON value. + * + * You should usually call [Builder.categories] with a well-typed [Categories] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun categories(categories: JsonField) = apply { + this.categories = categories + } - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** Alias for calling [categories] with `Categories.ofCategorical(categorical)`. */ + fun categoriesOfCategorical(categorical: List) = + categories(Categories.ofCategorical(categorical)) - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } + /** Alias for calling [categories] with `Categories.ofWeighted(weighted)`. */ + fun categories(weighted: Categories.Weighted) = + categories(Categories.ofWeighted(weighted)) - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } + /** Alias for calling [categories] with `Categories.ofMinimum(minimum)`. */ + fun categoriesOfMinimum(minimum: List) = + categories(Categories.ofMinimum(minimum)) - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + fun config(config: ProjectScoreConfig?) = config(JsonField.ofNullable(config)) - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** Alias for calling [Builder.config] with `config.orElse(null)`. */ + fun config(config: Optional) = config(config.getOrNull()) - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } + /** + * Sets [Builder.config] to an arbitrary JSON value. + * + * You should usually call [Builder.config] with a well-typed [ProjectScoreConfig] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun config(config: JsonField) = apply { this.config = config } - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } + /** Textual description of the project score */ + fun description(description: String?) = description(JsonField.ofNullable(description)) - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * .projectId() + * .scoreType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("name", name), + checkRequired("projectId", projectId), + checkRequired("scoreType", scoreType), + categories, + config, + description, + additionalProperties.toMutableMap(), + ) } - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } + private var validated: Boolean = false - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + fun validate(): Body = apply { + if (validated) { + return@apply } - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) + name() + projectId() + scoreType() + categories().ifPresent { it.validate() } + config().ifPresent { it.validate() } + description() + validated = true } - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + return /* spotless:off */ other is Body && name == other.name && projectId == other.projectId && scoreType == other.scoreType && categories == other.categories && config == other.config && description == other.description && additionalProperties == other.additionalProperties /* spotless:on */ } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) - } - - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(name, projectId, scoreType, categories, config, description, additionalProperties) } + /* spotless:on */ - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) - } + override fun hashCode(): Int = hashCode - /** - * Returns an immutable instance of [ProjectScoreReplaceParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * .projectId() - * .scoreType() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ProjectScoreReplaceParams = - ProjectScoreReplaceParams( - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + override fun toString() = + "Body{name=$name, projectId=$projectId, scoreType=$scoreType, categories=$categories, config=$config, description=$description, additionalProperties=$additionalProperties}" } /** For categorical-type project scores, the list of all categories */ @@ -923,27 +931,20 @@ private constructor( } /** For weighted-type project scores, the weights of each score */ - @NoAutoDetect class Weighted - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Weighted = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -990,7 +991,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Weighted = Weighted(additionalProperties.toImmutable()) + fun build(): Weighted = Weighted(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Weighted = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreRetrieveParams.kt index c6b4c52b..ee9e6b7c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreRetrieveParams.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers @@ -24,16 +23,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _pathParam(index: Int): String = - when (index) { - 0 -> projectScoreId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - fun toBuilder() = Builder().from(this) companion object { @@ -50,7 +39,6 @@ private constructor( } /** A builder for [ProjectScoreRetrieveParams]. */ - @NoAutoDetect class Builder internal constructor() { private var projectScoreId: String? = null @@ -185,6 +173,16 @@ private constructor( ) } + fun _pathParam(index: Int): String = + when (index) { + 0 -> projectScoreId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt index 27358edf..49e05343 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt @@ -8,14 +8,11 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -28,6 +25,7 @@ import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -127,574 +125,583 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body + fun toBuilder() = Builder().from(this) - fun _pathParam(index: Int): String = - when (index) { - 0 -> projectScoreId - else -> "" + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ProjectScoreUpdateParams]. + * + * The following fields are required: + * ```java + * .projectScoreId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProjectScoreUpdateParams]. */ + class Builder internal constructor() { + + private var projectScoreId: String? = null + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(projectScoreUpdateParams: ProjectScoreUpdateParams) = apply { + projectScoreId = projectScoreUpdateParams.projectScoreId + body = projectScoreUpdateParams.body.toBuilder() + additionalHeaders = projectScoreUpdateParams.additionalHeaders.toBuilder() + additionalQueryParams = projectScoreUpdateParams.additionalQueryParams.toBuilder() } - override fun _headers(): Headers = additionalHeaders + /** ProjectScore id */ + fun projectScoreId(projectScoreId: String) = apply { this.projectScoreId = projectScoreId } - override fun _queryParams(): QueryParams = additionalQueryParams + /** For categorical-type project scores, the list of all categories */ + fun categories(categories: Categories?) = apply { body.categories(categories) } - /** A project score is a user-configured score, which can be manually-labeled through the UI */ - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("categories") - @ExcludeMissing - private val categories: JsonField = JsonMissing.of(), - @JsonProperty("config") - @ExcludeMissing - private val config: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("score_type") - @ExcludeMissing - private val scoreType: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + /** Alias for calling [Builder.categories] with `categories.orElse(null)`. */ + fun categories(categories: Optional) = categories(categories.getOrNull()) /** - * For categorical-type project scores, the list of all categories + * Sets [Builder.categories] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.categories] with a well-typed [Categories] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun categories(): Optional = - Optional.ofNullable(categories.getNullable("categories")) + fun categories(categories: JsonField) = apply { body.categories(categories) } - /** - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun config(): Optional = - Optional.ofNullable(config.getNullable("config")) + /** Alias for calling [categories] with `Categories.ofCategorical(categorical)`. */ + fun categoriesOfCategorical(categorical: List) = apply { + body.categoriesOfCategorical(categorical) + } - /** - * Textual description of the project score - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + /** Alias for calling [categories] with `Categories.ofWeighted(weighted)`. */ + fun categories(weighted: Categories.Weighted) = apply { body.categories(weighted) } - /** - * Name of the project score - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + /** Alias for calling [categories] with `Categories.ofMinimum(minimum)`. */ + fun categoriesOfMinimum(minimum: List) = apply { body.categoriesOfMinimum(minimum) } - /** - * The type of the configured score - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun scoreType(): Optional = - Optional.ofNullable(scoreType.getNullable("score_type")) + fun config(config: ProjectScoreConfig?) = apply { body.config(config) } - /** - * Returns the raw JSON value of [categories]. - * - * Unlike [categories], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("categories") - @ExcludeMissing - fun _categories(): JsonField = categories + /** Alias for calling [Builder.config] with `config.orElse(null)`. */ + fun config(config: Optional) = config(config.getOrNull()) /** - * Returns the raw JSON value of [config]. + * Sets [Builder.config] to an arbitrary JSON value. * - * Unlike [config], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.config] with a well-typed [ProjectScoreConfig] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("config") - @ExcludeMissing - fun _config(): JsonField = config + fun config(config: JsonField) = apply { body.config(config) } - /** - * Returns the raw JSON value of [description]. - * - * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("description") - @ExcludeMissing - fun _description(): JsonField = description + /** Textual description of the project score */ + fun description(description: String?) = apply { body.description(description) } + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) /** - * Returns the raw JSON value of [name]. + * Sets [Builder.description] to an arbitrary JSON value. * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + fun description(description: JsonField) = apply { body.description(description) } + + /** Name of the project score */ + fun name(name: String?) = apply { body.name(name) } + + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) /** - * Returns the raw JSON value of [scoreType]. + * Sets [Builder.name] to an arbitrary JSON value. * - * Unlike [scoreType], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("score_type") - @ExcludeMissing - fun _scoreType(): JsonField = scoreType + fun name(name: JsonField) = apply { body.name(name) } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + /** The type of the configured score */ + fun scoreType(scoreType: ProjectScoreType?) = apply { body.scoreType(scoreType) } - private var validated: Boolean = false + /** Alias for calling [Builder.scoreType] with `scoreType.orElse(null)`. */ + fun scoreType(scoreType: Optional) = scoreType(scoreType.getOrNull()) - fun validate(): Body = apply { - if (validated) { - return@apply - } + /** + * Sets [Builder.scoreType] to an arbitrary JSON value. + * + * You should usually call [Builder.scoreType] with a well-typed [ProjectScoreType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun scoreType(scoreType: JsonField) = apply { body.scoreType(scoreType) } - categories().ifPresent { it.validate() } - config().ifPresent { it.validate() } - description() - name() - scoreType() - validated = true + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) } - fun toBuilder() = Builder().from(this) - - companion object { - - /** Returns a mutable builder for constructing an instance of [Body]. */ - @JvmStatic fun builder() = Builder() + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) } - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var categories: JsonField = JsonMissing.of() - private var config: JsonField = JsonMissing.of() - private var description: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var scoreType: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - categories = body.categories - config = body.config - description = body.description - name = body.name - scoreType = body.scoreType - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** For categorical-type project scores, the list of all categories */ - fun categories(categories: Categories?) = categories(JsonField.ofNullable(categories)) - - /** Alias for calling [Builder.categories] with `categories.orElse(null)`. */ - fun categories(categories: Optional) = categories(categories.getOrNull()) - - /** - * Sets [Builder.categories] to an arbitrary JSON value. - * - * You should usually call [Builder.categories] with a well-typed [Categories] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun categories(categories: JsonField) = apply { - this.categories = categories + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) } - /** Alias for calling [categories] with `Categories.ofCategorical(categorical)`. */ - fun categoriesOfCategorical(categorical: List) = - categories(Categories.ofCategorical(categorical)) - - /** Alias for calling [categories] with `Categories.ofWeighted(weighted)`. */ - fun categories(weighted: Categories.Weighted) = - categories(Categories.ofWeighted(weighted)) - - /** Alias for calling [categories] with `Categories.ofMinimum(minimum)`. */ - fun categoriesOfMinimum(minimum: List) = - categories(Categories.ofMinimum(minimum)) - - fun config(config: ProjectScoreConfig?) = config(JsonField.ofNullable(config)) + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - /** Alias for calling [Builder.config] with `config.orElse(null)`. */ - fun config(config: Optional) = config(config.getOrNull()) + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } - /** - * Sets [Builder.config] to an arbitrary JSON value. - * - * You should usually call [Builder.config] with a well-typed [ProjectScoreConfig] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun config(config: JsonField) = apply { this.config = config } + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** Textual description of the project score */ - fun description(description: String?) = description(JsonField.ofNullable(description)) + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun description(description: JsonField) = apply { - this.description = description - } + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - /** Name of the project score */ - fun name(name: String?) = name(JsonField.ofNullable(name)) + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** Alias for calling [Builder.name] with `name.orElse(null)`. */ - fun name(name: Optional) = name(name.getOrNull()) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - /** The type of the configured score */ - fun scoreType(scoreType: ProjectScoreType?) = scoreType(JsonField.ofNullable(scoreType)) + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** Alias for calling [Builder.scoreType] with `scoreType.orElse(null)`. */ - fun scoreType(scoreType: Optional) = scoreType(scoreType.getOrNull()) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Sets [Builder.scoreType] to an arbitrary JSON value. - * - * You should usually call [Builder.scoreType] with a well-typed [ProjectScoreType] - * value instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun scoreType(scoreType: JsonField) = apply { - this.scoreType = scoreType - } + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Body = - Body( - categories, - config, - description, - name, - scoreType, - additionalProperties.toImmutable(), - ) + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - return /* spotless:off */ other is Body && categories == other.categories && config == other.config && description == other.description && name == other.name && scoreType == other.scoreType && additionalProperties == other.additionalProperties /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(categories, config, description, name, scoreType, additionalProperties) } - /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } - override fun hashCode(): Int = hashCode + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - override fun toString() = - "Body{categories=$categories, config=$config, description=$description, name=$name, scoreType=$scoreType, additionalProperties=$additionalProperties}" - } + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - fun toBuilder() = Builder().from(this) + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - companion object { + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } /** - * Returns a mutable builder for constructing an instance of [ProjectScoreUpdateParams]. + * Returns an immutable instance of [ProjectScoreUpdateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java * .projectScoreId() * ``` + * + * @throws IllegalStateException if any required field is unset. */ - @JvmStatic fun builder() = Builder() + fun build(): ProjectScoreUpdateParams = + ProjectScoreUpdateParams( + checkRequired("projectScoreId", projectScoreId), + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) } - /** A builder for [ProjectScoreUpdateParams]. */ - @NoAutoDetect - class Builder internal constructor() { - - private var projectScoreId: String? = null - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + @JvmSynthetic internal fun _body(): Body = body - @JvmSynthetic - internal fun from(projectScoreUpdateParams: ProjectScoreUpdateParams) = apply { - projectScoreId = projectScoreUpdateParams.projectScoreId - body = projectScoreUpdateParams.body.toBuilder() - additionalHeaders = projectScoreUpdateParams.additionalHeaders.toBuilder() - additionalQueryParams = projectScoreUpdateParams.additionalQueryParams.toBuilder() + fun _pathParam(index: Int): String = + when (index) { + 0 -> projectScoreId + else -> "" } - /** ProjectScore id */ - fun projectScoreId(projectScoreId: String) = apply { this.projectScoreId = projectScoreId } + override fun _headers(): Headers = additionalHeaders - /** For categorical-type project scores, the list of all categories */ - fun categories(categories: Categories?) = apply { body.categories(categories) } + override fun _queryParams(): QueryParams = additionalQueryParams - /** Alias for calling [Builder.categories] with `categories.orElse(null)`. */ - fun categories(categories: Optional) = categories(categories.getOrNull()) + /** A project score is a user-configured score, which can be manually-labeled through the UI */ + class Body + private constructor( + private val categories: JsonField, + private val config: JsonField, + private val description: JsonField, + private val name: JsonField, + private val scoreType: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("categories") + @ExcludeMissing + categories: JsonField = JsonMissing.of(), + @JsonProperty("config") + @ExcludeMissing + config: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("score_type") + @ExcludeMissing + scoreType: JsonField = JsonMissing.of(), + ) : this(categories, config, description, name, scoreType, mutableMapOf()) /** - * Sets [Builder.categories] to an arbitrary JSON value. + * For categorical-type project scores, the list of all categories * - * You should usually call [Builder.categories] with a well-typed [Categories] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun categories(categories: JsonField) = apply { body.categories(categories) } - - /** Alias for calling [categories] with `Categories.ofCategorical(categorical)`. */ - fun categoriesOfCategorical(categorical: List) = apply { - body.categoriesOfCategorical(categorical) - } - - /** Alias for calling [categories] with `Categories.ofWeighted(weighted)`. */ - fun categories(weighted: Categories.Weighted) = apply { body.categories(weighted) } - - /** Alias for calling [categories] with `Categories.ofMinimum(minimum)`. */ - fun categoriesOfMinimum(minimum: List) = apply { body.categoriesOfMinimum(minimum) } - - fun config(config: ProjectScoreConfig?) = apply { body.config(config) } + fun categories(): Optional = + Optional.ofNullable(categories.getNullable("categories")) - /** Alias for calling [Builder.config] with `config.orElse(null)`. */ - fun config(config: Optional) = config(config.getOrNull()) + /** + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun config(): Optional = + Optional.ofNullable(config.getNullable("config")) /** - * Sets [Builder.config] to an arbitrary JSON value. + * Textual description of the project score * - * You should usually call [Builder.config] with a well-typed [ProjectScoreConfig] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun config(config: JsonField) = apply { body.config(config) } - - /** Textual description of the project score */ - fun description(description: String?) = apply { body.description(description) } - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) + fun description(): Optional = + Optional.ofNullable(description.getNullable("description")) /** - * Sets [Builder.description] to an arbitrary JSON value. + * Name of the project score * - * You should usually call [Builder.description] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun description(description: JsonField) = apply { body.description(description) } + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) - /** Name of the project score */ - fun name(name: String?) = apply { body.name(name) } + /** + * The type of the configured score + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun scoreType(): Optional = + Optional.ofNullable(scoreType.getNullable("score_type")) - /** Alias for calling [Builder.name] with `name.orElse(null)`. */ - fun name(name: Optional) = name(name.getOrNull()) + /** + * Returns the raw JSON value of [categories]. + * + * Unlike [categories], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("categories") + @ExcludeMissing + fun _categories(): JsonField = categories /** - * Sets [Builder.name] to an arbitrary JSON value. + * Returns the raw JSON value of [config]. * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [config], this method doesn't throw if the JSON field has an unexpected type. */ - fun name(name: JsonField) = apply { body.name(name) } + @JsonProperty("config") + @ExcludeMissing + fun _config(): JsonField = config - /** The type of the configured score */ - fun scoreType(scoreType: ProjectScoreType?) = apply { body.scoreType(scoreType) } + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description - /** Alias for calling [Builder.scoreType] with `scoreType.orElse(null)`. */ - fun scoreType(scoreType: Optional) = scoreType(scoreType.getOrNull()) + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name /** - * Sets [Builder.scoreType] to an arbitrary JSON value. + * Returns the raw JSON value of [scoreType]. * - * You should usually call [Builder.scoreType] with a well-typed [ProjectScoreType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * Unlike [scoreType], this method doesn't throw if the JSON field has an unexpected type. */ - fun scoreType(scoreType: JsonField) = apply { body.scoreType(scoreType) } + @JsonProperty("score_type") + @ExcludeMissing + fun _scoreType(): JsonField = scoreType + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Body]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var categories: JsonField = JsonMissing.of() + private var config: JsonField = JsonMissing.of() + private var description: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var scoreType: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + categories = body.categories + config = body.config + description = body.description + name = body.name + scoreType = body.scoreType + additionalProperties = body.additionalProperties.toMutableMap() + } - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) - } + /** For categorical-type project scores, the list of all categories */ + fun categories(categories: Categories?) = categories(JsonField.ofNullable(categories)) - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } + /** Alias for calling [Builder.categories] with `categories.orElse(null)`. */ + fun categories(categories: Optional) = categories(categories.getOrNull()) - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) + /** + * Sets [Builder.categories] to an arbitrary JSON value. + * + * You should usually call [Builder.categories] with a well-typed [Categories] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun categories(categories: JsonField) = apply { + this.categories = categories } - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + /** Alias for calling [categories] with `Categories.ofCategorical(categorical)`. */ + fun categoriesOfCategorical(categorical: List) = + categories(Categories.ofCategorical(categorical)) - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } + /** Alias for calling [categories] with `Categories.ofWeighted(weighted)`. */ + fun categories(weighted: Categories.Weighted) = + categories(Categories.ofWeighted(weighted)) - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** Alias for calling [categories] with `Categories.ofMinimum(minimum)`. */ + fun categoriesOfMinimum(minimum: List) = + categories(Categories.ofMinimum(minimum)) - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + fun config(config: ProjectScoreConfig?) = config(JsonField.ofNullable(config)) - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } + /** Alias for calling [Builder.config] with `config.orElse(null)`. */ + fun config(config: Optional) = config(config.getOrNull()) - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } + /** + * Sets [Builder.config] to an arbitrary JSON value. + * + * You should usually call [Builder.config] with a well-typed [ProjectScoreConfig] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun config(config: JsonField) = apply { this.config = config } - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** Textual description of the project score */ + fun description(description: String?) = description(JsonField.ofNullable(description)) - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } + /** Name of the project score */ + fun name(name: String?) = name(JsonField.ofNullable(name)) - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + /** The type of the configured score */ + fun scoreType(scoreType: ProjectScoreType?) = scoreType(JsonField.ofNullable(scoreType)) - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } + /** Alias for calling [Builder.scoreType] with `scoreType.orElse(null)`. */ + fun scoreType(scoreType: Optional) = scoreType(scoreType.getOrNull()) - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + /** + * Sets [Builder.scoreType] to an arbitrary JSON value. + * + * You should usually call [Builder.scoreType] with a well-typed [ProjectScoreType] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun scoreType(scoreType: JsonField) = apply { + this.scoreType = scoreType + } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Body = + Body( + categories, + config, + description, + name, + scoreType, + additionalProperties.toMutableMap(), + ) } - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } + private var validated: Boolean = false - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + fun validate(): Body = apply { + if (validated) { + return@apply + } + + categories().ifPresent { it.validate() } + config().ifPresent { it.validate() } + description() + name() + scoreType() + validated = true } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) + return /* spotless:off */ other is Body && categories == other.categories && config == other.config && description == other.description && name == other.name && scoreType == other.scoreType && additionalProperties == other.additionalProperties /* spotless:on */ } - /** - * Returns an immutable instance of [ProjectScoreUpdateParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .projectScoreId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ProjectScoreUpdateParams = - ProjectScoreUpdateParams( - checkRequired("projectScoreId", projectScoreId), - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(categories, config, description, name, scoreType, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{categories=$categories, config=$config, description=$description, name=$name, scoreType=$scoreType, additionalProperties=$additionalProperties}" } /** For categorical-type project scores, the list of all categories */ @@ -869,27 +876,20 @@ private constructor( } /** For weighted-type project scores, the weights of each score */ - @NoAutoDetect class Weighted - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Weighted = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -936,7 +936,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Weighted = Weighted(additionalProperties.toImmutable()) + fun build(): Weighted = Weighted(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Weighted = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectSettings.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectSettings.kt index 57bc8590..1da46df7 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectSettings.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectSettings.kt @@ -7,36 +7,40 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class ProjectSettings -@JsonCreator private constructor( - @JsonProperty("baseline_experiment_id") - @ExcludeMissing - private val baselineExperimentId: JsonField = JsonMissing.of(), - @JsonProperty("comparison_key") - @ExcludeMissing - private val comparisonKey: JsonField = JsonMissing.of(), - @JsonProperty("spanFieldOrder") - @ExcludeMissing - private val spanFieldOrder: JsonField> = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val baselineExperimentId: JsonField, + private val comparisonKey: JsonField, + private val spanFieldOrder: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("baseline_experiment_id") + @ExcludeMissing + baselineExperimentId: JsonField = JsonMissing.of(), + @JsonProperty("comparison_key") + @ExcludeMissing + comparisonKey: JsonField = JsonMissing.of(), + @JsonProperty("spanFieldOrder") + @ExcludeMissing + spanFieldOrder: JsonField> = JsonMissing.of(), + ) : this(baselineExperimentId, comparisonKey, spanFieldOrder, mutableMapOf()) + /** * The id of the experiment to use as the default baseline for comparisons * @@ -92,22 +96,15 @@ private constructor( @ExcludeMissing fun _spanFieldOrder(): JsonField> = spanFieldOrder + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): ProjectSettings = apply { - if (validated) { - return@apply - } - - baselineExperimentId() - comparisonKey() - spanFieldOrder().ifPresent { it.forEach { it.validate() } } - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -234,30 +231,46 @@ private constructor( baselineExperimentId, comparisonKey, (spanFieldOrder ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } - @NoAutoDetect + private var validated: Boolean = false + + fun validate(): ProjectSettings = apply { + if (validated) { + return@apply + } + + baselineExperimentId() + comparisonKey() + spanFieldOrder().ifPresent { it.forEach { it.validate() } } + validated = true + } + class SpanFieldOrder - @JsonCreator private constructor( - @JsonProperty("column_id") - @ExcludeMissing - private val columnId: JsonField = JsonMissing.of(), - @JsonProperty("object_type") - @ExcludeMissing - private val objectType: JsonField = JsonMissing.of(), - @JsonProperty("position") - @ExcludeMissing - private val position: JsonField = JsonMissing.of(), - @JsonProperty("layout") - @ExcludeMissing - private val layout: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val columnId: JsonField, + private val objectType: JsonField, + private val position: JsonField, + private val layout: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("column_id") + @ExcludeMissing + columnId: JsonField = JsonMissing.of(), + @JsonProperty("object_type") + @ExcludeMissing + objectType: JsonField = JsonMissing.of(), + @JsonProperty("position") + @ExcludeMissing + position: JsonField = JsonMissing.of(), + @JsonProperty("layout") @ExcludeMissing layout: JsonField = JsonMissing.of(), + ) : this(columnId, objectType, position, layout, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). @@ -312,23 +325,15 @@ private constructor( */ @JsonProperty("layout") @ExcludeMissing fun _layout(): JsonField = layout + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): SpanFieldOrder = apply { - if (validated) { - return@apply - } - - columnId() - objectType() - position() - layout() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -451,10 +456,24 @@ private constructor( checkRequired("objectType", objectType), checkRequired("position", position), layout, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): SpanFieldOrder = apply { + if (validated) { + return@apply + } + + columnId() + objectType() + position() + layout() + validated = true + } + class Layout @JsonCreator private constructor(private val value: JsonField) : Enum { /** diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTag.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTag.kt index 180ffb4e..4f34c11c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTag.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTag.kt @@ -6,16 +6,14 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -24,28 +22,33 @@ import kotlin.jvm.optionals.getOrNull * A project tag is a user-configured tag for tracking and filtering your experiments, logs, and * other data */ -@NoAutoDetect class ProjectTag -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing private val name: JsonField = JsonMissing.of(), - @JsonProperty("project_id") - @ExcludeMissing - private val projectId: JsonField = JsonMissing.of(), - @JsonProperty("user_id") - @ExcludeMissing - private val userId: JsonField = JsonMissing.of(), - @JsonProperty("color") @ExcludeMissing private val color: JsonField = JsonMissing.of(), - @JsonProperty("created") - @ExcludeMissing - private val created: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val name: JsonField, + private val projectId: JsonField, + private val userId: JsonField, + private val color: JsonField, + private val created: JsonField, + private val description: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("project_id") @ExcludeMissing projectId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), + @JsonProperty("color") @ExcludeMissing color: JsonField = JsonMissing.of(), + @JsonProperty("created") + @ExcludeMissing + created: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + ) : this(id, name, projectId, userId, color, created, description, mutableMapOf()) + /** * Unique identifier for the project tag * @@ -150,26 +153,15 @@ private constructor( */ @JsonProperty("description") @ExcludeMissing fun _description(): JsonField = description + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): ProjectTag = apply { - if (validated) { - return@apply - } - - id() - name() - projectId() - userId() - color() - created() - description() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -344,10 +336,27 @@ private constructor( color, created, description, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): ProjectTag = apply { + if (validated) { + return@apply + } + + id() + name() + projectId() + userId() + color() + created() + description() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagCreateParams.kt index ddb134a6..90fd333b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagCreateParams.kt @@ -6,18 +6,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -99,32 +97,253 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ProjectTagCreateParams]. + * + * The following fields are required: + * ```java + * .name() + * .projectId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProjectTagCreateParams]. */ + class Builder internal constructor() { + + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(projectTagCreateParams: ProjectTagCreateParams) = apply { + body = projectTagCreateParams.body.toBuilder() + additionalHeaders = projectTagCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = projectTagCreateParams.additionalQueryParams.toBuilder() + } + + /** Name of the project tag */ + fun name(name: String) = apply { body.name(name) } + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { body.name(name) } + + /** Unique identifier for the project that the project tag belongs under */ + fun projectId(projectId: String) = apply { body.projectId(projectId) } + + /** + * Sets [Builder.projectId] to an arbitrary JSON value. + * + * You should usually call [Builder.projectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun projectId(projectId: JsonField) = apply { body.projectId(projectId) } + + /** Color of the tag for the UI */ + fun color(color: String?) = apply { body.color(color) } + + /** Alias for calling [Builder.color] with `color.orElse(null)`. */ + fun color(color: Optional) = color(color.getOrNull()) + + /** + * Sets [Builder.color] to an arbitrary JSON value. + * + * You should usually call [Builder.color] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun color(color: JsonField) = apply { body.color(color) } + + /** Textual description of the project tag */ + fun description(description: String?) = apply { body.description(description) } + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun description(description: JsonField) = apply { body.description(description) } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(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 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) + } + + /** + * Returns an immutable instance of [ProjectTagCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * .projectId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProjectTagCreateParams = + ProjectTagCreateParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + @JvmSynthetic internal fun _body(): Body = body override fun _headers(): Headers = additionalHeaders override fun _queryParams(): QueryParams = additionalQueryParams - @NoAutoDetect class Body - @JsonCreator private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("project_id") - @ExcludeMissing - private val projectId: JsonField = JsonMissing.of(), - @JsonProperty("color") - @ExcludeMissing - private val color: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val name: JsonField, + private val projectId: JsonField, + private val color: JsonField, + private val description: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("color") @ExcludeMissing color: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + ) : this(name, projectId, color, description, mutableMapOf()) + /** * Name of the project tag * @@ -188,23 +407,15 @@ private constructor( @ExcludeMissing fun _description(): JsonField = description + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } - - name() - projectId() - color() - description() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -334,10 +545,24 @@ private constructor( checkRequired("projectId", projectId), color, description, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + name() + projectId() + color() + description() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -356,227 +581,6 @@ private constructor( "Body{name=$name, projectId=$projectId, color=$color, description=$description, additionalProperties=$additionalProperties}" } - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [ProjectTagCreateParams]. - * - * The following fields are required: - * ```java - * .name() - * .projectId() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [ProjectTagCreateParams]. */ - @NoAutoDetect - class Builder internal constructor() { - - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - - @JvmSynthetic - internal fun from(projectTagCreateParams: ProjectTagCreateParams) = apply { - body = projectTagCreateParams.body.toBuilder() - additionalHeaders = projectTagCreateParams.additionalHeaders.toBuilder() - additionalQueryParams = projectTagCreateParams.additionalQueryParams.toBuilder() - } - - /** Name of the project tag */ - fun name(name: String) = apply { body.name(name) } - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun name(name: JsonField) = apply { body.name(name) } - - /** Unique identifier for the project that the project tag belongs under */ - fun projectId(projectId: String) = apply { body.projectId(projectId) } - - /** - * Sets [Builder.projectId] to an arbitrary JSON value. - * - * You should usually call [Builder.projectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun projectId(projectId: JsonField) = apply { body.projectId(projectId) } - - /** Color of the tag for the UI */ - fun color(color: String?) = apply { body.color(color) } - - /** Alias for calling [Builder.color] with `color.orElse(null)`. */ - fun color(color: Optional) = color(color.getOrNull()) - - /** - * Sets [Builder.color] to an arbitrary JSON value. - * - * You should usually call [Builder.color] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun color(color: JsonField) = apply { body.color(color) } - - /** Textual description of the project tag */ - fun description(description: String?) = apply { body.description(description) } - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) - - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun description(description: JsonField) = apply { body.description(description) } - - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) - } - - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } - - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) - } - - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } - - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } - - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } - - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(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 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) - } - - /** - * Returns an immutable instance of [ProjectTagCreateParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * .projectId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ProjectTagCreateParams = - ProjectTagCreateParams( - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagDeleteParams.kt index 72050f9c..b3d6122f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagDeleteParams.kt @@ -2,13 +2,15 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.toImmutable +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import java.util.Collections import java.util.Objects import java.util.Optional @@ -18,7 +20,7 @@ private constructor( private val projectTagId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: Map, + private val additionalBodyProperties: MutableMap, ) : Params { /** ProjectTag id */ @@ -28,21 +30,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _additionalBodyProperties(): Map = additionalBodyProperties - - @JvmSynthetic - internal fun _body(): Optional> = - Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - - fun _pathParam(index: Int): String = - when (index) { - 0 -> projectTagId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders + @JsonAnySetter + private fun putAdditionalBodyProperty(key: String, value: JsonValue) { + additionalBodyProperties.put(key, value) + } - override fun _queryParams(): QueryParams = additionalQueryParams + @JsonAnyGetter + @ExcludeMissing + fun _additionalBodyProperties(): Map = + Collections.unmodifiableMap(additionalBodyProperties) fun toBuilder() = Builder().from(this) @@ -60,7 +56,6 @@ private constructor( } /** A builder for [ProjectTagDeleteParams]. */ - @NoAutoDetect class Builder internal constructor() { private var projectTagId: String? = null @@ -217,10 +212,24 @@ private constructor( checkRequired("projectTagId", projectTagId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toImmutable(), + additionalBodyProperties.toMutableMap(), ) } + @JvmSynthetic + internal fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> projectTagId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt index 59ff4610..a6be57ba 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.blocking.ProjectTagService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -90,24 +88,30 @@ private constructor( ) = ProjectTagListPage(projectTagsService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") - private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -165,7 +169,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt index d7ff05b7..43492662 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.async.ProjectTagServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -92,24 +90,30 @@ private constructor( ) = ProjectTagListPageAsync(projectTagsService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") - private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -169,7 +173,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListParams.kt index 9bc9a039..bf8907ac 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListParams.kt @@ -5,7 +5,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.BaseDeserializer import com.braintrustdata.api.core.BaseSerializer import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers @@ -83,33 +82,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = - QueryParams.builder() - .apply { - endingBefore?.let { put("ending_before", it) } - ids?.accept( - object : Ids.Visitor { - override fun visitString(string: String) { - put("ids", string) - } - - override fun visitStrings(strings: List) { - put("ids", strings.joinToString(",")) - } - } - ) - limit?.let { put("limit", it.toString()) } - orgName?.let { put("org_name", it) } - projectId?.let { put("project_id", it) } - projectName?.let { put("project_name", it) } - projectTagName?.let { put("project_tag_name", it) } - startingAfter?.let { put("starting_after", it) } - putAll(additionalQueryParams) - } - .build() - fun toBuilder() = Builder().from(this) companion object { @@ -121,7 +93,6 @@ private constructor( } /** A builder for [ProjectTagListParams]. */ - @NoAutoDetect class Builder internal constructor() { private var endingBefore: String? = null @@ -345,6 +316,33 @@ private constructor( ) } + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + endingBefore?.let { put("ending_before", it) } + ids?.accept( + object : Ids.Visitor { + override fun visitString(string: String) { + put("ids", string) + } + + override fun visitStrings(strings: List) { + put("ids", strings.joinToString(",")) + } + } + ) + limit?.let { put("limit", it.toString()) } + orgName?.let { put("org_name", it) } + projectId?.let { put("project_id", it) } + projectName?.let { put("project_name", it) } + projectTagName?.let { put("project_tag_name", it) } + startingAfter?.let { put("starting_after", it) } + putAll(additionalQueryParams) + } + .build() + /** * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagReplaceParams.kt index d4b0801e..e0f81a0e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagReplaceParams.kt @@ -6,18 +6,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -100,32 +98,253 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ProjectTagReplaceParams]. + * + * The following fields are required: + * ```java + * .name() + * .projectId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProjectTagReplaceParams]. */ + class Builder internal constructor() { + + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(projectTagReplaceParams: ProjectTagReplaceParams) = apply { + body = projectTagReplaceParams.body.toBuilder() + additionalHeaders = projectTagReplaceParams.additionalHeaders.toBuilder() + additionalQueryParams = projectTagReplaceParams.additionalQueryParams.toBuilder() + } + + /** Name of the project tag */ + fun name(name: String) = apply { body.name(name) } + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { body.name(name) } + + /** Unique identifier for the project that the project tag belongs under */ + fun projectId(projectId: String) = apply { body.projectId(projectId) } + + /** + * Sets [Builder.projectId] to an arbitrary JSON value. + * + * You should usually call [Builder.projectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun projectId(projectId: JsonField) = apply { body.projectId(projectId) } + + /** Color of the tag for the UI */ + fun color(color: String?) = apply { body.color(color) } + + /** Alias for calling [Builder.color] with `color.orElse(null)`. */ + fun color(color: Optional) = color(color.getOrNull()) + + /** + * Sets [Builder.color] to an arbitrary JSON value. + * + * You should usually call [Builder.color] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun color(color: JsonField) = apply { body.color(color) } + + /** Textual description of the project tag */ + fun description(description: String?) = apply { body.description(description) } + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun description(description: JsonField) = apply { body.description(description) } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(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 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) + } + + /** + * Returns an immutable instance of [ProjectTagReplaceParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * .projectId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProjectTagReplaceParams = + ProjectTagReplaceParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + @JvmSynthetic internal fun _body(): Body = body override fun _headers(): Headers = additionalHeaders override fun _queryParams(): QueryParams = additionalQueryParams - @NoAutoDetect class Body - @JsonCreator private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("project_id") - @ExcludeMissing - private val projectId: JsonField = JsonMissing.of(), - @JsonProperty("color") - @ExcludeMissing - private val color: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val name: JsonField, + private val projectId: JsonField, + private val color: JsonField, + private val description: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("color") @ExcludeMissing color: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + ) : this(name, projectId, color, description, mutableMapOf()) + /** * Name of the project tag * @@ -189,23 +408,15 @@ private constructor( @ExcludeMissing fun _description(): JsonField = description + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } - - name() - projectId() - color() - description() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -335,10 +546,24 @@ private constructor( checkRequired("projectId", projectId), color, description, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + name() + projectId() + color() + description() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -357,227 +582,6 @@ private constructor( "Body{name=$name, projectId=$projectId, color=$color, description=$description, additionalProperties=$additionalProperties}" } - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [ProjectTagReplaceParams]. - * - * The following fields are required: - * ```java - * .name() - * .projectId() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [ProjectTagReplaceParams]. */ - @NoAutoDetect - class Builder internal constructor() { - - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - - @JvmSynthetic - internal fun from(projectTagReplaceParams: ProjectTagReplaceParams) = apply { - body = projectTagReplaceParams.body.toBuilder() - additionalHeaders = projectTagReplaceParams.additionalHeaders.toBuilder() - additionalQueryParams = projectTagReplaceParams.additionalQueryParams.toBuilder() - } - - /** Name of the project tag */ - fun name(name: String) = apply { body.name(name) } - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun name(name: JsonField) = apply { body.name(name) } - - /** Unique identifier for the project that the project tag belongs under */ - fun projectId(projectId: String) = apply { body.projectId(projectId) } - - /** - * Sets [Builder.projectId] to an arbitrary JSON value. - * - * You should usually call [Builder.projectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun projectId(projectId: JsonField) = apply { body.projectId(projectId) } - - /** Color of the tag for the UI */ - fun color(color: String?) = apply { body.color(color) } - - /** Alias for calling [Builder.color] with `color.orElse(null)`. */ - fun color(color: Optional) = color(color.getOrNull()) - - /** - * Sets [Builder.color] to an arbitrary JSON value. - * - * You should usually call [Builder.color] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun color(color: JsonField) = apply { body.color(color) } - - /** Textual description of the project tag */ - fun description(description: String?) = apply { body.description(description) } - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) - - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun description(description: JsonField) = apply { body.description(description) } - - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) - } - - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } - - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) - } - - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } - - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } - - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } - - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(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 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) - } - - /** - * Returns an immutable instance of [ProjectTagReplaceParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * .projectId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ProjectTagReplaceParams = - ProjectTagReplaceParams( - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagRetrieveParams.kt index 286a939e..20c3485b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagRetrieveParams.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers @@ -24,16 +23,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _pathParam(index: Int): String = - when (index) { - 0 -> projectTagId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - fun toBuilder() = Builder().from(this) companion object { @@ -50,7 +39,6 @@ private constructor( } /** A builder for [ProjectTagRetrieveParams]. */ - @NoAutoDetect class Builder internal constructor() { private var projectTagId: String? = null @@ -185,6 +173,16 @@ private constructor( ) } + fun _pathParam(index: Int): String = + when (index) { + 0 -> projectTagId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParams.kt index c9570330..e92812b0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParams.kt @@ -6,18 +6,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -89,216 +87,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - fun _pathParam(index: Int): String = - when (index) { - 0 -> projectTagId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("color") - @ExcludeMissing - private val color: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { - - /** - * Color of the tag for the UI - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun color(): Optional = Optional.ofNullable(color.getNullable("color")) - - /** - * Textual description of the project tag - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) - - /** - * Name of the project tag - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) - - /** - * Returns the raw JSON value of [color]. - * - * Unlike [color], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("color") @ExcludeMissing fun _color(): JsonField = color - - /** - * Returns the raw JSON value of [description]. - * - * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("description") - @ExcludeMissing - fun _description(): JsonField = description - - /** - * Returns the raw JSON value of [name]. - * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } - - color() - description() - name() - validated = true - } - - fun toBuilder() = Builder().from(this) - - companion object { - - /** Returns a mutable builder for constructing an instance of [Body]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var color: JsonField = JsonMissing.of() - private var description: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - color = body.color - description = body.description - name = body.name - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** Color of the tag for the UI */ - fun color(color: String?) = color(JsonField.ofNullable(color)) - - /** Alias for calling [Builder.color] with `color.orElse(null)`. */ - fun color(color: Optional) = color(color.getOrNull()) - - /** - * Sets [Builder.color] to an arbitrary JSON value. - * - * You should usually call [Builder.color] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun color(color: JsonField) = apply { this.color = color } - - /** Textual description of the project tag */ - fun description(description: String?) = description(JsonField.ofNullable(description)) - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) - - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun description(description: JsonField) = apply { - this.description = description - } - - /** Name of the project tag */ - fun name(name: String?) = name(JsonField.ofNullable(name)) - - /** Alias for calling [Builder.name] with `name.orElse(null)`. */ - fun name(name: Optional) = name(name.getOrNull()) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - 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) - } - - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Body = Body(color, description, name, additionalProperties.toImmutable()) - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Body && color == other.color && description == other.description && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(color, description, name, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Body{color=$color, description=$description, name=$name, additionalProperties=$additionalProperties}" - } - fun toBuilder() = Builder().from(this) companion object { @@ -315,7 +103,6 @@ private constructor( } /** A builder for [ProjectTagUpdateParams]. */ - @NoAutoDetect class Builder internal constructor() { private var projectTagId: String? = null @@ -515,6 +302,222 @@ private constructor( ) } + @JvmSynthetic internal fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> projectTagId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val color: JsonField, + private val description: JsonField, + private val name: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("color") @ExcludeMissing color: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + ) : this(color, description, name, mutableMapOf()) + + /** + * Color of the tag for the UI + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun color(): Optional = Optional.ofNullable(color.getNullable("color")) + + /** + * Textual description of the project tag + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun description(): Optional = + Optional.ofNullable(description.getNullable("description")) + + /** + * Name of the project tag + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + /** + * Returns the raw JSON value of [color]. + * + * Unlike [color], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("color") @ExcludeMissing fun _color(): JsonField = color + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Body]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var color: JsonField = JsonMissing.of() + private var description: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + color = body.color + description = body.description + name = body.name + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** Color of the tag for the UI */ + fun color(color: String?) = color(JsonField.ofNullable(color)) + + /** Alias for calling [Builder.color] with `color.orElse(null)`. */ + fun color(color: Optional) = color(color.getOrNull()) + + /** + * Sets [Builder.color] to an arbitrary JSON value. + * + * You should usually call [Builder.color] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun color(color: JsonField) = apply { this.color = color } + + /** Textual description of the project tag */ + fun description(description: String?) = description(JsonField.ofNullable(description)) + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } + + /** Name of the project tag */ + fun name(name: String?) = name(JsonField.ofNullable(name)) + + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Body = Body(color, description, name, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + color() + description() + name() + validated = true + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && color == other.color && description == other.description && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(color, description, name, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{color=$color, description=$description, name=$name, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectUpdateParams.kt index 19fd07cc..69964f2c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectUpdateParams.kt @@ -6,18 +6,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -75,182 +73,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - fun _pathParam(index: Int): String = - when (index) { - 0 -> projectId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("settings") - @ExcludeMissing - private val settings: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { - - /** - * Name of the project - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) - - /** - * Project settings. Patch operations replace all settings, so make sure you include all - * settings you want to keep. - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun settings(): Optional = - Optional.ofNullable(settings.getNullable("settings")) - - /** - * Returns the raw JSON value of [name]. - * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - - /** - * Returns the raw JSON value of [settings]. - * - * Unlike [settings], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("settings") - @ExcludeMissing - fun _settings(): JsonField = settings - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } - - name() - settings().ifPresent { it.validate() } - validated = true - } - - fun toBuilder() = Builder().from(this) - - companion object { - - /** Returns a mutable builder for constructing an instance of [Body]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var name: JsonField = JsonMissing.of() - private var settings: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - name = body.name - settings = body.settings - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** Name of the project */ - fun name(name: String?) = name(JsonField.ofNullable(name)) - - /** Alias for calling [Builder.name] with `name.orElse(null)`. */ - fun name(name: Optional) = name(name.getOrNull()) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } - - /** - * Project settings. Patch operations replace all settings, so make sure you include all - * settings you want to keep. - */ - fun settings(settings: ProjectSettings?) = settings(JsonField.ofNullable(settings)) - - /** Alias for calling [Builder.settings] with `settings.orElse(null)`. */ - fun settings(settings: Optional) = settings(settings.getOrNull()) - - /** - * Sets [Builder.settings] to an arbitrary JSON value. - * - * You should usually call [Builder.settings] with a well-typed [ProjectSettings] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun settings(settings: JsonField) = apply { this.settings = settings } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - 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) - } - - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Body = Body(name, settings, additionalProperties.toImmutable()) - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Body && name == other.name && settings == other.settings && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, settings, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Body{name=$name, settings=$settings, additionalProperties=$additionalProperties}" - } - fun toBuilder() = Builder().from(this) companion object { @@ -267,7 +89,6 @@ private constructor( } /** A builder for [ProjectUpdateParams]. */ - @NoAutoDetect class Builder internal constructor() { private var projectId: String? = null @@ -456,6 +277,189 @@ private constructor( ) } + @JvmSynthetic internal fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> projectId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val name: JsonField, + private val settings: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("settings") + @ExcludeMissing + settings: JsonField = JsonMissing.of(), + ) : this(name, settings, mutableMapOf()) + + /** + * Name of the project + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + /** + * Project settings. Patch operations replace all settings, so make sure you include all + * settings you want to keep. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun settings(): Optional = + Optional.ofNullable(settings.getNullable("settings")) + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [settings]. + * + * Unlike [settings], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("settings") + @ExcludeMissing + fun _settings(): JsonField = settings + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Body]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var name: JsonField = JsonMissing.of() + private var settings: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + name = body.name + settings = body.settings + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** Name of the project */ + fun name(name: String?) = name(JsonField.ofNullable(name)) + + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** + * Project settings. Patch operations replace all settings, so make sure you include all + * settings you want to keep. + */ + fun settings(settings: ProjectSettings?) = settings(JsonField.ofNullable(settings)) + + /** Alias for calling [Builder.settings] with `settings.orElse(null)`. */ + fun settings(settings: Optional) = settings(settings.getOrNull()) + + /** + * Sets [Builder.settings] to an arbitrary JSON value. + * + * You should usually call [Builder.settings] with a well-typed [ProjectSettings] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun settings(settings: JsonField) = apply { this.settings = settings } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Body = Body(name, settings, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + name() + settings().ifPresent { it.validate() } + validated = true + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && name == other.name && settings == other.settings && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(name, settings, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{name=$name, settings=$settings, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Prompt.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Prompt.kt index aa64928b..9adc2473 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Prompt.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Prompt.kt @@ -7,10 +7,8 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter @@ -18,46 +16,69 @@ import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class Prompt -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("_xact_id") - @ExcludeMissing - private val _xactId: JsonField = JsonMissing.of(), - @JsonProperty("log_id") @ExcludeMissing private val logId: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing private val name: JsonField = JsonMissing.of(), - @JsonProperty("org_id") @ExcludeMissing private val orgId: JsonField = JsonMissing.of(), - @JsonProperty("project_id") - @ExcludeMissing - private val projectId: JsonField = JsonMissing.of(), - @JsonProperty("slug") @ExcludeMissing private val slug: JsonField = JsonMissing.of(), - @JsonProperty("created") - @ExcludeMissing - private val created: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("function_type") - @ExcludeMissing - private val functionType: JsonField = JsonMissing.of(), - @JsonProperty("metadata") - @ExcludeMissing - private val metadata: JsonField = JsonMissing.of(), - @JsonProperty("prompt_data") - @ExcludeMissing - private val promptData: JsonField = JsonMissing.of(), - @JsonProperty("tags") - @ExcludeMissing - private val tags: JsonField> = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val _xactId: JsonField, + private val logId: JsonField, + private val name: JsonField, + private val orgId: JsonField, + private val projectId: JsonField, + private val slug: JsonField, + private val created: JsonField, + private val description: JsonField, + private val functionType: JsonField, + private val metadata: JsonField, + private val promptData: JsonField, + private val tags: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("_xact_id") @ExcludeMissing _xactId: JsonField = JsonMissing.of(), + @JsonProperty("log_id") @ExcludeMissing logId: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("org_id") @ExcludeMissing orgId: JsonField = JsonMissing.of(), + @JsonProperty("project_id") @ExcludeMissing projectId: JsonField = JsonMissing.of(), + @JsonProperty("slug") @ExcludeMissing slug: JsonField = JsonMissing.of(), + @JsonProperty("created") + @ExcludeMissing + created: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("function_type") + @ExcludeMissing + functionType: JsonField = JsonMissing.of(), + @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("prompt_data") + @ExcludeMissing + promptData: JsonField = JsonMissing.of(), + @JsonProperty("tags") @ExcludeMissing tags: JsonField> = JsonMissing.of(), + ) : this( + id, + _xactId, + logId, + name, + orgId, + projectId, + slug, + created, + description, + functionType, + metadata, + promptData, + tags, + mutableMapOf(), + ) + /** * Unique identifier for the prompt * @@ -260,32 +281,15 @@ private constructor( */ @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Prompt = apply { - if (validated) { - return@apply - } - - id() - _xactId() - logId() - name() - orgId() - projectId() - slug() - created() - description() - functionType() - metadata().ifPresent { it.validate() } - promptData().ifPresent { it.validate() } - tags() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -582,10 +586,33 @@ private constructor( metadata, promptData, (tags ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Prompt = apply { + if (validated) { + return@apply + } + + id() + _xactId() + logId() + name() + orgId() + projectId() + slug() + created() + description() + functionType() + metadata().ifPresent { it.validate() } + promptData().ifPresent { it.validate() } + tags() + validated = true + } + /** A literal 'p' which identifies the object as a project prompt */ class LogId @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -797,27 +824,20 @@ private constructor( } /** User-controlled metadata about the prompt */ - @NoAutoDetect class Metadata - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -861,7 +881,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptCreateParams.kt index a7e0dcef..eeb396bc 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptCreateParams.kt @@ -7,19 +7,18 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -144,401 +143,261 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams + fun toBuilder() = Builder().from(this) - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("project_id") - @ExcludeMissing - private val projectId: JsonField = JsonMissing.of(), - @JsonProperty("slug") - @ExcludeMissing - private val slug: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("function_type") - @ExcludeMissing - private val functionType: JsonField = JsonMissing.of(), - @JsonProperty("prompt_data") - @ExcludeMissing - private val promptData: JsonField = JsonMissing.of(), - @JsonProperty("tags") - @ExcludeMissing - private val tags: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + companion object { /** - * Name of the prompt + * Returns a mutable builder for constructing an instance of [PromptCreateParams]. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + * The following fields are required: + * ```java + * .name() + * .projectId() + * .slug() + * ``` */ - fun name(): String = name.getRequired("name") + @JvmStatic fun builder() = Builder() + } - /** - * Unique identifier for the project that the prompt belongs under - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun projectId(): String = projectId.getRequired("project_id") + /** A builder for [PromptCreateParams]. */ + class Builder internal constructor() { - /** - * Unique identifier for the prompt - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun slug(): String = slug.getRequired("slug") + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - /** - * Textual description of the prompt - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + @JvmSynthetic + internal fun from(promptCreateParams: PromptCreateParams) = apply { + body = promptCreateParams.body.toBuilder() + additionalHeaders = promptCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = promptCreateParams.additionalQueryParams.toBuilder() + } - /** - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun functionType(): Optional = - Optional.ofNullable(functionType.getNullable("function_type")) + /** Name of the prompt */ + fun name(name: String) = apply { body.name(name) } /** - * The prompt, model, and its parameters + * Sets [Builder.name] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun promptData(): Optional = - Optional.ofNullable(promptData.getNullable("prompt_data")) + fun name(name: JsonField) = apply { body.name(name) } - /** - * A list of tags for the prompt - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) + /** Unique identifier for the project that the prompt belongs under */ + fun projectId(projectId: String) = apply { body.projectId(projectId) } /** - * Returns the raw JSON value of [name]. + * Sets [Builder.projectId] to an arbitrary JSON value. * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.projectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + fun projectId(projectId: JsonField) = apply { body.projectId(projectId) } + + /** Unique identifier for the prompt */ + fun slug(slug: String) = apply { body.slug(slug) } /** - * Returns the raw JSON value of [projectId]. + * Sets [Builder.slug] to an arbitrary JSON value. * - * Unlike [projectId], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.slug] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("project_id") @ExcludeMissing fun _projectId(): JsonField = projectId + fun slug(slug: JsonField) = apply { body.slug(slug) } + + /** Textual description of the prompt */ + fun description(description: String?) = apply { body.description(description) } + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) /** - * Returns the raw JSON value of [slug]. + * Sets [Builder.description] to an arbitrary JSON value. * - * Unlike [slug], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("slug") @ExcludeMissing fun _slug(): JsonField = slug + fun description(description: JsonField) = apply { body.description(description) } + + fun functionType(functionType: FunctionType?) = apply { body.functionType(functionType) } + + /** Alias for calling [Builder.functionType] with `functionType.orElse(null)`. */ + fun functionType(functionType: Optional) = + functionType(functionType.getOrNull()) /** - * Returns the raw JSON value of [description]. + * Sets [Builder.functionType] to an arbitrary JSON value. * - * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.functionType] with a well-typed [FunctionType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("description") - @ExcludeMissing - fun _description(): JsonField = description + fun functionType(functionType: JsonField) = apply { + body.functionType(functionType) + } + + /** The prompt, model, and its parameters */ + fun promptData(promptData: PromptData?) = apply { body.promptData(promptData) } + + /** Alias for calling [Builder.promptData] with `promptData.orElse(null)`. */ + fun promptData(promptData: Optional) = promptData(promptData.getOrNull()) /** - * Returns the raw JSON value of [functionType]. + * Sets [Builder.promptData] to an arbitrary JSON value. * - * Unlike [functionType], this method doesn't throw if the JSON field has an unexpected - * type. + * You should usually call [Builder.promptData] with a well-typed [PromptData] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("function_type") - @ExcludeMissing - fun _functionType(): JsonField = functionType + fun promptData(promptData: JsonField) = apply { body.promptData(promptData) } + + /** A list of tags for the prompt */ + fun tags(tags: List?) = apply { body.tags(tags) } + + /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ + fun tags(tags: Optional>) = tags(tags.getOrNull()) /** - * Returns the raw JSON value of [promptData]. + * Sets [Builder.tags] to an arbitrary JSON value. * - * Unlike [promptData], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.tags] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("prompt_data") - @ExcludeMissing - fun _promptData(): JsonField = promptData + fun tags(tags: JsonField>) = apply { body.tags(tags) } /** - * Returns the raw JSON value of [tags]. + * Adds a single [String] to [tags]. * - * Unlike [tags], this method doesn't throw if the JSON field has an unexpected type. + * @throws IllegalStateException if the field was previously set to a non-list. */ - @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags + fun addTag(tag: String) = apply { body.addTag(tag) } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } - private var validated: Boolean = false + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } - fun validate(): Body = apply { - if (validated) { - return@apply + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) } - name() - projectId() - slug() - description() - functionType() - promptData().ifPresent { it.validate() } - tags() - validated = true + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) } - fun toBuilder() = Builder().from(this) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - companion object { + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .name() - * .projectId() - * .slug() - * ``` - */ - @JvmStatic fun builder() = Builder() + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - /** A builder for [Body]. */ - class Builder internal constructor() { + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - private var name: JsonField? = null - private var projectId: JsonField? = null - private var slug: JsonField? = null - private var description: JsonField = JsonMissing.of() - private var functionType: JsonField = JsonMissing.of() - private var promptData: JsonField = JsonMissing.of() - private var tags: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - @JvmSynthetic - internal fun from(body: Body) = apply { - name = body.name - projectId = body.projectId - slug = body.slug - description = body.description - functionType = body.functionType - promptData = body.promptData - tags = body.tags.map { it.toMutableList() } - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** Name of the prompt */ - fun name(name: String) = name(JsonField.of(name)) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } - - /** Unique identifier for the project that the prompt belongs under */ - fun projectId(projectId: String) = projectId(JsonField.of(projectId)) - - /** - * Sets [Builder.projectId] to an arbitrary JSON value. - * - * You should usually call [Builder.projectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun projectId(projectId: JsonField) = apply { this.projectId = projectId } - - /** Unique identifier for the prompt */ - fun slug(slug: String) = slug(JsonField.of(slug)) - - /** - * Sets [Builder.slug] to an arbitrary JSON value. - * - * You should usually call [Builder.slug] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun slug(slug: JsonField) = apply { this.slug = slug } - - /** Textual description of the prompt */ - fun description(description: String?) = description(JsonField.ofNullable(description)) - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) - - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun description(description: JsonField) = apply { - this.description = description - } - - fun functionType(functionType: FunctionType?) = - functionType(JsonField.ofNullable(functionType)) - - /** Alias for calling [Builder.functionType] with `functionType.orElse(null)`. */ - fun functionType(functionType: Optional) = - functionType(functionType.getOrNull()) - - /** - * Sets [Builder.functionType] to an arbitrary JSON value. - * - * You should usually call [Builder.functionType] with a well-typed [FunctionType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun functionType(functionType: JsonField) = apply { - this.functionType = functionType - } - - /** The prompt, model, and its parameters */ - fun promptData(promptData: PromptData?) = promptData(JsonField.ofNullable(promptData)) - - /** Alias for calling [Builder.promptData] with `promptData.orElse(null)`. */ - fun promptData(promptData: Optional) = promptData(promptData.getOrNull()) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** - * Sets [Builder.promptData] to an arbitrary JSON value. - * - * You should usually call [Builder.promptData] with a well-typed [PromptData] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun promptData(promptData: JsonField) = apply { - this.promptData = promptData - } + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - /** A list of tags for the prompt */ - fun tags(tags: List?) = tags(JsonField.ofNullable(tags)) + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ - fun tags(tags: Optional>) = tags(tags.getOrNull()) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Sets [Builder.tags] to an arbitrary JSON value. - * - * You should usually call [Builder.tags] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun tags(tags: JsonField>) = apply { - this.tags = tags.map { it.toMutableList() } - } + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Adds a single [String] to [tags]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addTag(tag: String) = apply { - tags = - (tags ?: JsonField.of(mutableListOf())).also { checkKnown("tags", it).add(tag) } - } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * .projectId() - * .slug() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("name", name), - checkRequired("projectId", projectId), - checkRequired("slug", slug), - description, - functionType, - promptData, - (tags ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), - ) + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - return /* spotless:off */ other is Body && name == other.name && projectId == other.projectId && slug == other.slug && description == other.description && functionType == other.functionType && promptData == other.promptData && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, projectId, slug, description, functionType, promptData, tags, additionalProperties) } - /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } - override fun hashCode(): Int = hashCode + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - override fun toString() = - "Body{name=$name, projectId=$projectId, slug=$slug, description=$description, functionType=$functionType, promptData=$promptData, tags=$tags, additionalProperties=$additionalProperties}" - } + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - fun toBuilder() = Builder().from(this) + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - companion object { + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } /** - * Returns a mutable builder for constructing an instance of [PromptCreateParams]. + * Returns an immutable instance of [PromptCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java @@ -546,265 +405,412 @@ private constructor( * .projectId() * .slug() * ``` + * + * @throws IllegalStateException if any required field is unset. */ - @JvmStatic fun builder() = Builder() + fun build(): PromptCreateParams = + PromptCreateParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) } - /** A builder for [PromptCreateParams]. */ - @NoAutoDetect - class Builder internal constructor() { + @JvmSynthetic internal fun _body(): Body = body - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun from(promptCreateParams: PromptCreateParams) = apply { - body = promptCreateParams.body.toBuilder() - additionalHeaders = promptCreateParams.additionalHeaders.toBuilder() - additionalQueryParams = promptCreateParams.additionalQueryParams.toBuilder() - } + override fun _queryParams(): QueryParams = additionalQueryParams - /** Name of the prompt */ - fun name(name: String) = apply { body.name(name) } + class Body + private constructor( + private val name: JsonField, + private val projectId: JsonField, + private val slug: JsonField, + private val description: JsonField, + private val functionType: JsonField, + private val promptData: JsonField, + private val tags: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("slug") @ExcludeMissing slug: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("function_type") + @ExcludeMissing + functionType: JsonField = JsonMissing.of(), + @JsonProperty("prompt_data") + @ExcludeMissing + promptData: JsonField = JsonMissing.of(), + @JsonProperty("tags") @ExcludeMissing tags: JsonField> = JsonMissing.of(), + ) : this(name, projectId, slug, description, functionType, promptData, tags, mutableMapOf()) /** - * Sets [Builder.name] to an arbitrary JSON value. + * Name of the prompt * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun name(name: JsonField) = apply { body.name(name) } - - /** Unique identifier for the project that the prompt belongs under */ - fun projectId(projectId: String) = apply { body.projectId(projectId) } + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") /** - * Sets [Builder.projectId] to an arbitrary JSON value. + * Unique identifier for the project that the prompt belongs under * - * You should usually call [Builder.projectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun projectId(projectId: JsonField) = apply { body.projectId(projectId) } - - /** Unique identifier for the prompt */ - fun slug(slug: String) = apply { body.slug(slug) } + fun projectId(): String = projectId.getRequired("project_id") /** - * Sets [Builder.slug] to an arbitrary JSON value. + * Unique identifier for the prompt * - * You should usually call [Builder.slug] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun slug(slug: JsonField) = apply { body.slug(slug) } - - /** Textual description of the prompt */ - fun description(description: String?) = apply { body.description(description) } - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) + fun slug(): String = slug.getRequired("slug") /** - * Sets [Builder.description] to an arbitrary JSON value. + * Textual description of the prompt * - * You should usually call [Builder.description] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun description(description: JsonField) = apply { body.description(description) } + fun description(): Optional = + Optional.ofNullable(description.getNullable("description")) - fun functionType(functionType: FunctionType?) = apply { body.functionType(functionType) } + /** + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun functionType(): Optional = + Optional.ofNullable(functionType.getNullable("function_type")) - /** Alias for calling [Builder.functionType] with `functionType.orElse(null)`. */ - fun functionType(functionType: Optional) = - functionType(functionType.getOrNull()) + /** + * The prompt, model, and its parameters + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun promptData(): Optional = + Optional.ofNullable(promptData.getNullable("prompt_data")) /** - * Sets [Builder.functionType] to an arbitrary JSON value. + * A list of tags for the prompt * - * You should usually call [Builder.functionType] with a well-typed [FunctionType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun functionType(functionType: JsonField) = apply { - body.functionType(functionType) - } + fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) - /** The prompt, model, and its parameters */ - fun promptData(promptData: PromptData?) = apply { body.promptData(promptData) } + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - /** Alias for calling [Builder.promptData] with `promptData.orElse(null)`. */ - fun promptData(promptData: Optional) = promptData(promptData.getOrNull()) + /** + * Returns the raw JSON value of [projectId]. + * + * Unlike [projectId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("project_id") @ExcludeMissing fun _projectId(): JsonField = projectId /** - * Sets [Builder.promptData] to an arbitrary JSON value. + * Returns the raw JSON value of [slug]. * - * You should usually call [Builder.promptData] with a well-typed [PromptData] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * Unlike [slug], this method doesn't throw if the JSON field has an unexpected type. */ - fun promptData(promptData: JsonField) = apply { body.promptData(promptData) } + @JsonProperty("slug") @ExcludeMissing fun _slug(): JsonField = slug - /** A list of tags for the prompt */ - fun tags(tags: List?) = apply { body.tags(tags) } + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description - /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ - fun tags(tags: Optional>) = tags(tags.getOrNull()) + /** + * Returns the raw JSON value of [functionType]. + * + * Unlike [functionType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("function_type") + @ExcludeMissing + fun _functionType(): JsonField = functionType /** - * Sets [Builder.tags] to an arbitrary JSON value. + * Returns the raw JSON value of [promptData]. * - * You should usually call [Builder.tags] with a well-typed `List` value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [promptData], this method doesn't throw if the JSON field has an unexpected type. */ - fun tags(tags: JsonField>) = apply { body.tags(tags) } + @JsonProperty("prompt_data") + @ExcludeMissing + fun _promptData(): JsonField = promptData /** - * Adds a single [String] to [tags]. + * Returns the raw JSON value of [tags]. * - * @throws IllegalStateException if the field was previously set to a non-list. + * Unlike [tags], this method doesn't throw if the JSON field has an unexpected type. */ - fun addTag(tag: String) = apply { body.addTag(tag) } + @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .name() + * .projectId() + * .slug() + * ``` + */ + @JvmStatic fun builder() = Builder() } - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var name: JsonField? = null + private var projectId: JsonField? = null + private var slug: JsonField? = null + private var description: JsonField = JsonMissing.of() + private var functionType: JsonField = JsonMissing.of() + private var promptData: JsonField = JsonMissing.of() + private var tags: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + name = body.name + projectId = body.projectId + slug = body.slug + description = body.description + functionType = body.functionType + promptData = body.promptData + tags = body.tags.map { it.toMutableList() } + additionalProperties = body.additionalProperties.toMutableMap() } - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + /** Name of the prompt */ + fun name(name: String) = name(JsonField.of(name)) - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** Unique identifier for the project that the prompt belongs under */ + fun projectId(projectId: String) = projectId(JsonField.of(projectId)) - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * Sets [Builder.projectId] to an arbitrary JSON value. + * + * You should usually call [Builder.projectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun projectId(projectId: JsonField) = apply { this.projectId = projectId } - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } + /** Unique identifier for the prompt */ + fun slug(slug: String) = slug(JsonField.of(slug)) - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } + /** + * Sets [Builder.slug] to an arbitrary JSON value. + * + * You should usually call [Builder.slug] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun slug(slug: JsonField) = apply { this.slug = slug } - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** Textual description of the prompt */ + fun description(description: String?) = description(JsonField.ofNullable(description)) - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } + fun functionType(functionType: FunctionType?) = + functionType(JsonField.ofNullable(functionType)) - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** Alias for calling [Builder.functionType] with `functionType.orElse(null)`. */ + fun functionType(functionType: Optional) = + functionType(functionType.getOrNull()) - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** + * Sets [Builder.functionType] to an arbitrary JSON value. + * + * You should usually call [Builder.functionType] with a well-typed [FunctionType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun functionType(functionType: JsonField) = apply { + this.functionType = functionType + } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + /** The prompt, model, and its parameters */ + fun promptData(promptData: PromptData?) = promptData(JsonField.ofNullable(promptData)) - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } + /** Alias for calling [Builder.promptData] with `promptData.orElse(null)`. */ + fun promptData(promptData: Optional) = promptData(promptData.getOrNull()) - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + /** + * Sets [Builder.promptData] to an arbitrary JSON value. + * + * You should usually call [Builder.promptData] with a well-typed [PromptData] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun promptData(promptData: JsonField) = apply { + this.promptData = promptData + } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + /** A list of tags for the prompt */ + fun tags(tags: List?) = tags(JsonField.ofNullable(tags)) - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } + /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ + fun tags(tags: Optional>) = tags(tags.getOrNull()) - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) - } + /** + * Sets [Builder.tags] to an arbitrary JSON value. + * + * You should usually call [Builder.tags] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tags(tags: JsonField>) = apply { + this.tags = tags.map { it.toMutableList() } + } - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } + /** + * Adds a single [String] to [tags]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTag(tag: String) = apply { + tags = + (tags ?: JsonField.of(mutableListOf())).also { checkKnown("tags", it).add(tag) } + } - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) } - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * .projectId() + * .slug() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("name", name), + checkRequired("projectId", projectId), + checkRequired("slug", slug), + description, + functionType, + promptData, + (tags ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply } - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + name() + projectId() + slug() + description() + functionType() + promptData().ifPresent { it.validate() } + tags() + validated = true + } - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && name == other.name && projectId == other.projectId && slug == other.slug && description == other.description && functionType == other.functionType && promptData == other.promptData && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ } - /** - * Returns an immutable instance of [PromptCreateParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * .projectId() - * .slug() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): PromptCreateParams = - PromptCreateParams( - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(name, projectId, slug, description, functionType, promptData, tags, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{name=$name, projectId=$projectId, slug=$slug, description=$description, functionType=$functionType, promptData=$promptData, tags=$tags, additionalProperties=$additionalProperties}" } class FunctionType @JsonCreator private constructor(private val value: JsonField) : diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptData.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptData.kt index c47b3a79..844aa180 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptData.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptData.kt @@ -9,11 +9,9 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter @@ -27,33 +25,35 @@ import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull /** The prompt, model, and its parameters */ -@NoAutoDetect class PromptData -@JsonCreator private constructor( - @JsonProperty("options") - @ExcludeMissing - private val options: JsonField = JsonMissing.of(), - @JsonProperty("origin") - @ExcludeMissing - private val origin: JsonField = JsonMissing.of(), - @JsonProperty("parser") - @ExcludeMissing - private val parser: JsonField = JsonMissing.of(), - @JsonProperty("prompt") - @ExcludeMissing - private val prompt: JsonField = JsonMissing.of(), - @JsonProperty("tool_functions") - @ExcludeMissing - private val toolFunctions: JsonField> = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val options: JsonField, + private val origin: JsonField, + private val parser: JsonField, + private val prompt: JsonField, + private val toolFunctions: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("options") + @ExcludeMissing + options: JsonField = JsonMissing.of(), + @JsonProperty("origin") @ExcludeMissing origin: JsonField = JsonMissing.of(), + @JsonProperty("parser") @ExcludeMissing parser: JsonField = JsonMissing.of(), + @JsonProperty("prompt") @ExcludeMissing prompt: JsonField = JsonMissing.of(), + @JsonProperty("tool_functions") + @ExcludeMissing + toolFunctions: JsonField> = JsonMissing.of(), + ) : this(options, origin, parser, prompt, toolFunctions, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -122,24 +122,15 @@ private constructor( @ExcludeMissing fun _toolFunctions(): JsonField> = toolFunctions + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): PromptData = apply { - if (validated) { - return@apply - } - - options().ifPresent { it.validate() } - origin().ifPresent { it.validate() } - parser().ifPresent { it.validate() } - prompt().ifPresent { it.validate() } - toolFunctions().ifPresent { it.forEach { it.validate() } } - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -297,27 +288,46 @@ private constructor( parser, prompt, (toolFunctions ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } - @NoAutoDetect + private var validated: Boolean = false + + fun validate(): PromptData = apply { + if (validated) { + return@apply + } + + options().ifPresent { it.validate() } + origin().ifPresent { it.validate() } + parser().ifPresent { it.validate() } + prompt().ifPresent { it.validate() } + toolFunctions().ifPresent { it.forEach { it.validate() } } + validated = true + } + class Origin - @JsonCreator private constructor( - @JsonProperty("project_id") - @ExcludeMissing - private val projectId: JsonField = JsonMissing.of(), - @JsonProperty("prompt_id") - @ExcludeMissing - private val promptId: JsonField = JsonMissing.of(), - @JsonProperty("prompt_version") - @ExcludeMissing - private val promptVersion: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val projectId: JsonField, + private val promptId: JsonField, + private val promptVersion: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("prompt_id") + @ExcludeMissing + promptId: JsonField = JsonMissing.of(), + @JsonProperty("prompt_version") + @ExcludeMissing + promptVersion: JsonField = JsonMissing.of(), + ) : this(projectId, promptId, promptVersion, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). @@ -361,22 +371,15 @@ private constructor( @ExcludeMissing fun _promptVersion(): JsonField = promptVersion + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Origin = apply { - if (validated) { - return@apply - } - - projectId() - promptId() - promptVersion() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -462,7 +465,20 @@ private constructor( * Further updates to this [Builder] will not mutate the returned instance. */ fun build(): Origin = - Origin(projectId, promptId, promptVersion, additionalProperties.toImmutable()) + Origin(projectId, promptId, promptVersion, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Origin = apply { + if (validated) { + return@apply + } + + projectId() + promptId() + promptVersion() + validated = true } override fun equals(other: Any?): Boolean { @@ -483,21 +499,23 @@ private constructor( "Origin{projectId=$projectId, promptId=$promptId, promptVersion=$promptVersion, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Parser - @JsonCreator private constructor( - @JsonProperty("choice_scores") - @ExcludeMissing - private val choiceScores: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing private val type: JsonField = JsonMissing.of(), - @JsonProperty("use_cot") - @ExcludeMissing - private val useCot: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val choiceScores: JsonField, + private val type: JsonField, + private val useCot: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("choice_scores") + @ExcludeMissing + choiceScores: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("use_cot") @ExcludeMissing useCot: JsonField = JsonMissing.of(), + ) : this(choiceScores, type, useCot, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). @@ -540,22 +558,15 @@ private constructor( */ @JsonProperty("use_cot") @ExcludeMissing fun _useCot(): JsonField = useCot + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Parser = apply { - if (validated) { - return@apply - } - - choiceScores().validate() - type() - useCot() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -663,32 +674,38 @@ private constructor( checkRequired("choiceScores", choiceScores), checkRequired("type", type), checkRequired("useCot", useCot), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } - @NoAutoDetect - class ChoiceScores - @JsonCreator - private constructor( - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private var validated: Boolean = false - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun validate(): Parser = apply { + if (validated) { + return@apply + } - private var validated: Boolean = false + choiceScores().validate() + type() + useCot() + validated = true + } - fun validate(): ChoiceScores = apply { - if (validated) { - return@apply - } + class ChoiceScores + private constructor(private val additionalProperties: MutableMap) { - validated = true + @JsonCreator private constructor() : this(mutableMapOf()) + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + fun toBuilder() = Builder().from(this) companion object { @@ -734,7 +751,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): ChoiceScores = ChoiceScores(additionalProperties.toImmutable()) + fun build(): ChoiceScores = ChoiceScores(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): ChoiceScores = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { @@ -999,20 +1026,21 @@ private constructor( } } - @NoAutoDetect class Completion - @JsonCreator private constructor( - @JsonProperty("content") - @ExcludeMissing - private val content: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val content: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("content") + @ExcludeMissing + content: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(content, type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -1041,21 +1069,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Completion = apply { - if (validated) { - return@apply - } - - content() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1148,10 +1170,22 @@ private constructor( Completion( checkRequired("content", content), checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Completion = apply { + if (validated) { + return@apply + } + + content() + type() + validated = true + } + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -1267,23 +1301,23 @@ private constructor( "Completion{content=$content, type=$type, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Chat - @JsonCreator private constructor( - @JsonProperty("messages") - @ExcludeMissing - private val messages: JsonField> = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonProperty("tools") - @ExcludeMissing - private val tools: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val messages: JsonField>, + private val type: JsonField, + private val tools: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("messages") + @ExcludeMissing + messages: JsonField> = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("tools") @ExcludeMissing tools: JsonField = JsonMissing.of(), + ) : this(messages, type, tools, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -1328,22 +1362,15 @@ private constructor( */ @JsonProperty("tools") @ExcludeMissing fun _tools(): JsonField = tools + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Chat = apply { - if (validated) { - return@apply - } - - messages().forEach { it.validate() } - type() - tools() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1485,10 +1512,23 @@ private constructor( checkRequired("messages", messages).map { it.toImmutable() }, checkRequired("type", type), tools, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Chat = apply { + if (validated) { + return@apply + } + + messages().forEach { it.validate() } + type() + tools() + validated = true + } + @JsonDeserialize(using = Message.Deserializer::class) @JsonSerialize(using = Message.Serializer::class) class Message @@ -1714,23 +1754,27 @@ private constructor( } } - @NoAutoDetect class System - @JsonCreator private constructor( - @JsonProperty("role") - @ExcludeMissing - private val role: JsonField = JsonMissing.of(), - @JsonProperty("content") - @ExcludeMissing - private val content: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val role: JsonField, + private val content: JsonField, + private val name: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("role") + @ExcludeMissing + role: JsonField = JsonMissing.of(), + @JsonProperty("content") + @ExcludeMissing + content: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + ) : this(role, content, name, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type or is unexpectedly missing or null (e.g. if the server responded with @@ -1777,22 +1821,15 @@ private constructor( */ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): System = apply { - if (validated) { - return@apply - } - - role() - content() - name() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1898,10 +1935,23 @@ private constructor( checkRequired("role", role), content, name, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): System = apply { + if (validated) { + return@apply + } + + role() + content() + name() + validated = true + } + class Role @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2021,23 +2071,27 @@ private constructor( "System{role=$role, content=$content, name=$name, additionalProperties=$additionalProperties}" } - @NoAutoDetect class User - @JsonCreator private constructor( - @JsonProperty("role") - @ExcludeMissing - private val role: JsonField = JsonMissing.of(), - @JsonProperty("content") - @ExcludeMissing - private val content: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val role: JsonField, + private val content: JsonField, + private val name: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("role") + @ExcludeMissing + role: JsonField = JsonMissing.of(), + @JsonProperty("content") + @ExcludeMissing + content: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + ) : this(role, content, name, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type or is unexpectedly missing or null (e.g. if the server responded with @@ -2084,22 +2138,15 @@ private constructor( */ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): User = apply { - if (validated) { - return@apply - } - - role() - content().ifPresent { it.validate() } - name() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -2212,10 +2259,23 @@ private constructor( checkRequired("role", role), content, name, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): User = apply { + if (validated) { + return@apply + } + + role() + content().ifPresent { it.validate() } + name() + validated = true + } + class Role @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2662,30 +2722,35 @@ private constructor( "User{role=$role, content=$content, name=$name, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Assistant - @JsonCreator private constructor( - @JsonProperty("role") - @ExcludeMissing - private val role: JsonField = JsonMissing.of(), - @JsonProperty("content") - @ExcludeMissing - private val content: JsonField = JsonMissing.of(), - @JsonProperty("function_call") - @ExcludeMissing - private val functionCall: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("tool_calls") - @ExcludeMissing - private val toolCalls: JsonField> = - JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val role: JsonField, + private val content: JsonField, + private val functionCall: JsonField, + private val name: JsonField, + private val toolCalls: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("role") + @ExcludeMissing + role: JsonField = JsonMissing.of(), + @JsonProperty("content") + @ExcludeMissing + content: JsonField = JsonMissing.of(), + @JsonProperty("function_call") + @ExcludeMissing + functionCall: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("tool_calls") + @ExcludeMissing + toolCalls: JsonField> = JsonMissing.of(), + ) : this(role, content, functionCall, name, toolCalls, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type or is unexpectedly missing or null (e.g. if the server responded with @@ -2766,24 +2831,15 @@ private constructor( @ExcludeMissing fun _toolCalls(): JsonField> = toolCalls + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Assistant = apply { - if (validated) { - return@apply - } - - role() - content() - functionCall().ifPresent { it.validate() } - name() - toolCalls().ifPresent { it.forEach { it.validate() } } - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -2957,10 +3013,25 @@ private constructor( functionCall, name, (toolCalls ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Assistant = apply { + if (validated) { + return@apply + } + + role() + content() + functionCall().ifPresent { it.validate() } + name() + toolCalls().ifPresent { it.forEach { it.validate() } } + validated = true + } + class Role @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -3062,21 +3133,23 @@ private constructor( override fun toString() = value.toString() } - @NoAutoDetect class FunctionCall - @JsonCreator private constructor( - @JsonProperty("arguments") - @ExcludeMissing - private val arguments: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = - immutableEmptyMap(), + private val arguments: JsonField, + private val name: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("arguments") + @ExcludeMissing + arguments: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + ) : this(arguments, name, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an * unexpected type or is unexpectedly missing or null (e.g. if the server @@ -3109,21 +3182,15 @@ private constructor( */ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): FunctionCall = apply { - if (validated) { - return@apply - } - - arguments() - name() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -3222,10 +3289,22 @@ private constructor( FunctionCall( checkRequired("arguments", arguments), checkRequired("name", name), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): FunctionCall = apply { + if (validated) { + return@apply + } + + arguments() + name() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3262,23 +3341,27 @@ private constructor( "Assistant{role=$role, content=$content, functionCall=$functionCall, name=$name, toolCalls=$toolCalls, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Tool - @JsonCreator private constructor( - @JsonProperty("role") - @ExcludeMissing - private val role: JsonField = JsonMissing.of(), - @JsonProperty("content") - @ExcludeMissing - private val content: JsonField = JsonMissing.of(), - @JsonProperty("tool_call_id") - @ExcludeMissing - private val toolCallId: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val role: JsonField, + private val content: JsonField, + private val toolCallId: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("role") + @ExcludeMissing + role: JsonField = JsonMissing.of(), + @JsonProperty("content") + @ExcludeMissing + content: JsonField = JsonMissing.of(), + @JsonProperty("tool_call_id") + @ExcludeMissing + toolCallId: JsonField = JsonMissing.of(), + ) : this(role, content, toolCallId, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type or is unexpectedly missing or null (e.g. if the server responded with @@ -3328,22 +3411,15 @@ private constructor( @ExcludeMissing fun _toolCallId(): JsonField = toolCallId + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Tool = apply { - if (validated) { - return@apply - } - - role() - content() - toolCallId() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -3451,10 +3527,23 @@ private constructor( checkRequired("role", role), content, toolCallId, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Tool = apply { + if (validated) { + return@apply + } + + role() + content() + toolCallId() + validated = true + } + class Role @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -3574,23 +3663,27 @@ private constructor( "Tool{role=$role, content=$content, toolCallId=$toolCallId, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Function - @JsonCreator private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("role") - @ExcludeMissing - private val role: JsonField = JsonMissing.of(), - @JsonProperty("content") - @ExcludeMissing - private val content: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val name: JsonField, + private val role: JsonField, + private val content: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("role") + @ExcludeMissing + role: JsonField = JsonMissing.of(), + @JsonProperty("content") + @ExcludeMissing + content: JsonField = JsonMissing.of(), + ) : this(name, role, content, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type or is unexpectedly missing or null (e.g. if the server responded with @@ -3638,22 +3731,15 @@ private constructor( @ExcludeMissing fun _content(): JsonField = content + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Function = apply { - if (validated) { - return@apply - } - - name() - role() - content() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -3761,10 +3847,23 @@ private constructor( checkRequired("name", name), checkRequired("role", role), content, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Function = apply { + if (validated) { + return@apply + } + + name() + role() + content() + validated = true + } + class Role @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -3884,20 +3983,23 @@ private constructor( "Function{name=$name, role=$role, content=$content, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Fallback - @JsonCreator private constructor( - @JsonProperty("role") - @ExcludeMissing - private val role: JsonField = JsonMissing.of(), - @JsonProperty("content") - @ExcludeMissing - private val content: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val role: JsonField, + private val content: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("role") + @ExcludeMissing + role: JsonField = JsonMissing.of(), + @JsonProperty("content") + @ExcludeMissing + content: JsonField = JsonMissing.of(), + ) : this(role, content, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type or is unexpectedly missing or null (e.g. if the server responded with @@ -3930,21 +4032,15 @@ private constructor( @ExcludeMissing fun _content(): JsonField = content + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Fallback = apply { - if (validated) { - return@apply - } - - role() - content() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -4039,10 +4135,22 @@ private constructor( Fallback( checkRequired("role", role), content, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Fallback = apply { + if (validated) { + return@apply + } + + role() + content() + validated = true + } + class Role @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -4415,20 +4523,19 @@ private constructor( } } - @NoAutoDetect class Function - @JsonCreator private constructor( - @JsonProperty("id") - @ExcludeMissing - private val id: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(id, type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -4457,21 +4564,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Function = apply { - if (validated) { - return@apply - } - - id() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -4564,10 +4665,22 @@ private constructor( Function( checkRequired("id", id), checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Function = apply { + if (validated) { + return@apply + } + + id() + type() + validated = true + } + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -4683,20 +4796,19 @@ private constructor( "Function{id=$id, type=$type, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Global - @JsonCreator private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val name: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(name, type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -4725,21 +4837,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Global = apply { - if (validated) { - return@apply - } - - name() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -4832,10 +4938,22 @@ private constructor( Global( checkRequired("name", name), checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Global = apply { + if (validated) { + return@apply + } + + name() + type() + validated = true + } + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptDeleteParams.kt index 5815825a..d4ae1f6b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptDeleteParams.kt @@ -2,13 +2,15 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.toImmutable +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import java.util.Collections import java.util.Objects import java.util.Optional @@ -18,7 +20,7 @@ private constructor( private val promptId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: Map, + private val additionalBodyProperties: MutableMap, ) : Params { /** Prompt id */ @@ -28,21 +30,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _additionalBodyProperties(): Map = additionalBodyProperties - - @JvmSynthetic - internal fun _body(): Optional> = - Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - - fun _pathParam(index: Int): String = - when (index) { - 0 -> promptId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders + @JsonAnySetter + private fun putAdditionalBodyProperty(key: String, value: JsonValue) { + additionalBodyProperties.put(key, value) + } - override fun _queryParams(): QueryParams = additionalQueryParams + @JsonAnyGetter + @ExcludeMissing + fun _additionalBodyProperties(): Map = + Collections.unmodifiableMap(additionalBodyProperties) fun toBuilder() = Builder().from(this) @@ -60,7 +56,6 @@ private constructor( } /** A builder for [PromptDeleteParams]. */ - @NoAutoDetect class Builder internal constructor() { private var promptId: String? = null @@ -216,10 +211,24 @@ private constructor( checkRequired("promptId", promptId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toImmutable(), + additionalBodyProperties.toMutableMap(), ) } + @JvmSynthetic + internal fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> promptId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt index 54e69368..86a417c9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.blocking.PromptService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -81,23 +79,30 @@ private constructor( PromptListPage(promptsService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -155,7 +160,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt index d360b8a7..3be8e4a9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.async.PromptServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -83,23 +81,30 @@ private constructor( PromptListPageAsync(promptsService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -157,7 +162,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListParams.kt index d5c704fa..09d243ab 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListParams.kt @@ -5,7 +5,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.BaseDeserializer import com.braintrustdata.api.core.BaseSerializer import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers @@ -96,35 +95,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = - QueryParams.builder() - .apply { - endingBefore?.let { put("ending_before", it) } - ids?.accept( - object : Ids.Visitor { - override fun visitString(string: String) { - put("ids", string) - } - - override fun visitStrings(strings: List) { - put("ids", strings.joinToString(",")) - } - } - ) - limit?.let { put("limit", it.toString()) } - orgName?.let { put("org_name", it) } - projectId?.let { put("project_id", it) } - projectName?.let { put("project_name", it) } - promptName?.let { put("prompt_name", it) } - slug?.let { put("slug", it) } - startingAfter?.let { put("starting_after", it) } - version?.let { put("version", it) } - putAll(additionalQueryParams) - } - .build() - fun toBuilder() = Builder().from(this) companion object { @@ -136,7 +106,6 @@ private constructor( } /** A builder for [PromptListParams]. */ - @NoAutoDetect class Builder internal constructor() { private var endingBefore: String? = null @@ -382,6 +351,35 @@ private constructor( ) } + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + endingBefore?.let { put("ending_before", it) } + ids?.accept( + object : Ids.Visitor { + override fun visitString(string: String) { + put("ids", string) + } + + override fun visitStrings(strings: List) { + put("ids", strings.joinToString(",")) + } + } + ) + limit?.let { put("limit", it.toString()) } + orgName?.let { put("org_name", it) } + projectId?.let { put("project_id", it) } + projectName?.let { put("project_name", it) } + promptName?.let { put("prompt_name", it) } + slug?.let { put("slug", it) } + startingAfter?.let { put("starting_after", it) } + version?.let { put("version", it) } + putAll(additionalQueryParams) + } + .build() + /** * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptOptions.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptOptions.kt index c13395bf..6d100afe 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptOptions.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptOptions.kt @@ -9,11 +9,9 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter @@ -27,24 +25,26 @@ import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class PromptOptions -@JsonCreator private constructor( - @JsonProperty("model") @ExcludeMissing private val model: JsonField = JsonMissing.of(), - @JsonProperty("params") - @ExcludeMissing - private val params: JsonField = JsonMissing.of(), - @JsonProperty("position") - @ExcludeMissing - private val position: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val model: JsonField, + private val params: JsonField, + private val position: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("model") @ExcludeMissing model: JsonField = JsonMissing.of(), + @JsonProperty("params") @ExcludeMissing params: JsonField = JsonMissing.of(), + @JsonProperty("position") @ExcludeMissing position: JsonField = JsonMissing.of(), + ) : this(model, params, position, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -84,22 +84,15 @@ private constructor( */ @JsonProperty("position") @ExcludeMissing fun _position(): JsonField = position + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): PromptOptions = apply { - if (validated) { - return@apply - } - - model() - params().ifPresent { it.validate() } - position() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -200,7 +193,20 @@ private constructor( * Further updates to this [Builder] will not mutate the returned instance. */ fun build(): PromptOptions = - PromptOptions(model, params, position, additionalProperties.toImmutable()) + PromptOptions(model, params, position, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): PromptOptions = apply { + if (validated) { + return@apply + } + + model() + params().ifPresent { it.validate() } + position() + validated = true } @JsonDeserialize(using = Params.Deserializer::class) @@ -410,51 +416,78 @@ private constructor( } } - @NoAutoDetect class OpenAIModelParams - @JsonCreator private constructor( - @JsonProperty("frequency_penalty") - @ExcludeMissing - private val frequencyPenalty: JsonField = JsonMissing.of(), - @JsonProperty("function_call") - @ExcludeMissing - private val functionCall: JsonField = JsonMissing.of(), - @JsonProperty("max_completion_tokens") - @ExcludeMissing - private val maxCompletionTokens: JsonField = JsonMissing.of(), - @JsonProperty("max_tokens") - @ExcludeMissing - private val maxTokens: JsonField = JsonMissing.of(), - @JsonProperty("n") @ExcludeMissing private val n: JsonField = JsonMissing.of(), - @JsonProperty("presence_penalty") - @ExcludeMissing - private val presencePenalty: JsonField = JsonMissing.of(), - @JsonProperty("reasoning_effort") - @ExcludeMissing - private val reasoningEffort: JsonField = JsonMissing.of(), - @JsonProperty("response_format") - @ExcludeMissing - private val responseFormat: JsonField = JsonMissing.of(), - @JsonProperty("stop") - @ExcludeMissing - private val stop: JsonField> = JsonMissing.of(), - @JsonProperty("temperature") - @ExcludeMissing - private val temperature: JsonField = JsonMissing.of(), - @JsonProperty("tool_choice") - @ExcludeMissing - private val toolChoice: JsonField = JsonMissing.of(), - @JsonProperty("top_p") - @ExcludeMissing - private val topP: JsonField = JsonMissing.of(), - @JsonProperty("use_cache") - @ExcludeMissing - private val useCache: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val frequencyPenalty: JsonField, + private val functionCall: JsonField, + private val maxCompletionTokens: JsonField, + private val maxTokens: JsonField, + private val n: JsonField, + private val presencePenalty: JsonField, + private val reasoningEffort: JsonField, + private val responseFormat: JsonField, + private val stop: JsonField>, + private val temperature: JsonField, + private val toolChoice: JsonField, + private val topP: JsonField, + private val useCache: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("frequency_penalty") + @ExcludeMissing + frequencyPenalty: JsonField = JsonMissing.of(), + @JsonProperty("function_call") + @ExcludeMissing + functionCall: JsonField = JsonMissing.of(), + @JsonProperty("max_completion_tokens") + @ExcludeMissing + maxCompletionTokens: JsonField = JsonMissing.of(), + @JsonProperty("max_tokens") + @ExcludeMissing + maxTokens: JsonField = JsonMissing.of(), + @JsonProperty("n") @ExcludeMissing n: JsonField = JsonMissing.of(), + @JsonProperty("presence_penalty") + @ExcludeMissing + presencePenalty: JsonField = JsonMissing.of(), + @JsonProperty("reasoning_effort") + @ExcludeMissing + reasoningEffort: JsonField = JsonMissing.of(), + @JsonProperty("response_format") + @ExcludeMissing + responseFormat: JsonField = JsonMissing.of(), + @JsonProperty("stop") + @ExcludeMissing + stop: JsonField> = JsonMissing.of(), + @JsonProperty("temperature") + @ExcludeMissing + temperature: JsonField = JsonMissing.of(), + @JsonProperty("tool_choice") + @ExcludeMissing + toolChoice: JsonField = JsonMissing.of(), + @JsonProperty("top_p") @ExcludeMissing topP: JsonField = JsonMissing.of(), + @JsonProperty("use_cache") + @ExcludeMissing + useCache: JsonField = JsonMissing.of(), + ) : this( + frequencyPenalty, + functionCall, + maxCompletionTokens, + maxTokens, + n, + presencePenalty, + reasoningEffort, + responseFormat, + stop, + temperature, + toolChoice, + topP, + useCache, + mutableMapOf(), + ) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). @@ -666,32 +699,15 @@ private constructor( @ExcludeMissing fun _useCache(): JsonField = useCache + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): OpenAIModelParams = apply { - if (validated) { - return@apply - } - - frequencyPenalty() - functionCall().ifPresent { it.validate() } - maxCompletionTokens() - maxTokens() - n() - presencePenalty() - reasoningEffort() - responseFormat().ifPresent { it.validate() } - stop() - temperature() - toolChoice().ifPresent { it.validate() } - topP() - useCache() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1006,10 +1022,33 @@ private constructor( toolChoice, topP, useCache, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): OpenAIModelParams = apply { + if (validated) { + return@apply + } + + frequencyPenalty() + functionCall().ifPresent { it.validate() } + maxCompletionTokens() + maxTokens() + n() + presencePenalty() + reasoningEffort() + responseFormat().ifPresent { it.validate() } + stop() + temperature() + toolChoice().ifPresent { it.validate() } + topP() + useCache() + validated = true + } + @JsonDeserialize(using = FunctionCall.Deserializer::class) @JsonSerialize(using = FunctionCall.Serializer::class) class FunctionCall @@ -1255,17 +1294,19 @@ private constructor( override fun toString() = value.toString() } - @NoAutoDetect class Function - @JsonCreator private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val name: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of() + ) : this(name, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type or is unexpectedly missing or null (e.g. if the server responded with @@ -1281,20 +1322,15 @@ private constructor( */ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Function = apply { - if (validated) { - return@apply - } - - name() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1372,10 +1408,21 @@ private constructor( fun build(): Function = Function( checkRequired("name", name), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Function = apply { + if (validated) { + return@apply + } + + name() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1672,17 +1719,19 @@ private constructor( } } - @NoAutoDetect class JsonObject - @JsonCreator private constructor( - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of() + ) : this(type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type or is unexpectedly missing or null (e.g. if the server responded with @@ -1698,20 +1747,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): JsonObject = apply { - if (validated) { - return@apply - } - - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1789,10 +1833,21 @@ private constructor( fun build(): JsonObject = JsonObject( checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): JsonObject = apply { + if (validated) { + return@apply + } + + type() + validated = true + } + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -1912,20 +1967,23 @@ private constructor( "JsonObject{type=$type, additionalProperties=$additionalProperties}" } - @NoAutoDetect class JsonSchema - @JsonCreator private constructor( - @JsonProperty("json_schema") - @ExcludeMissing - private val jsonSchema: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val jsonSchema: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("json_schema") + @ExcludeMissing + jsonSchema: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + ) : this(jsonSchema, type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type or is unexpectedly missing or null (e.g. if the server responded with @@ -1958,21 +2016,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): JsonSchema = apply { - if (validated) { - return@apply - } - - jsonSchema().validate() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -2069,31 +2121,47 @@ private constructor( JsonSchema( checkRequired("jsonSchema", jsonSchema), checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } - @NoAutoDetect + private var validated: Boolean = false + + fun validate(): JsonSchema = apply { + if (validated) { + return@apply + } + + jsonSchema().validate() + type() + validated = true + } + class InnerJsonSchema - @JsonCreator private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("schema") - @ExcludeMissing - private val schema: JsonField = JsonMissing.of(), - @JsonProperty("strict") - @ExcludeMissing - private val strict: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = - immutableEmptyMap(), + private val name: JsonField, + private val description: JsonField, + private val schema: JsonField, + private val strict: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("schema") + @ExcludeMissing + schema: JsonField = JsonMissing.of(), + @JsonProperty("strict") + @ExcludeMissing + strict: JsonField = JsonMissing.of(), + ) : this(name, description, schema, strict, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an * unexpected type or is unexpectedly missing or null (e.g. if the server @@ -2163,23 +2231,15 @@ private constructor( @ExcludeMissing fun _strict(): JsonField = strict + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): InnerJsonSchema = apply { - if (validated) { - return@apply - } - - name() - description() - schema().ifPresent { it.validate() } - strict() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -2321,10 +2381,24 @@ private constructor( description, schema, strict, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): InnerJsonSchema = apply { + if (validated) { + return@apply + } + + name() + description() + schema().ifPresent { it.validate() } + strict() + validated = true + } + @JsonDeserialize(using = Schema.Deserializer::class) @JsonSerialize(using = Schema.Serializer::class) class Schema @@ -2460,30 +2534,23 @@ private constructor( } } - @NoAutoDetect class Object - @JsonCreator private constructor( - @JsonAnySetter - private val additionalProperties: Map = - immutableEmptyMap() + private val additionalProperties: MutableMap ) { - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - additionalProperties - - private var validated: Boolean = false - - fun validate(): Object = apply { - if (validated) { - return@apply - } + @JsonCreator private constructor() : this(mutableMapOf()) - validated = true + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + fun toBuilder() = Builder().from(this) companion object { @@ -2540,7 +2607,18 @@ private constructor( * Further updates to this [Builder] will not mutate the * returned instance. */ - fun build(): Object = Object(additionalProperties.toImmutable()) + fun build(): Object = + Object(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Object = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { @@ -2699,17 +2777,19 @@ private constructor( "JsonSchema{jsonSchema=$jsonSchema, type=$type, additionalProperties=$additionalProperties}" } - @NoAutoDetect class Text - @JsonCreator private constructor( - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of() + ) : this(type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type or is unexpectedly missing or null (e.g. if the server responded with @@ -2725,20 +2805,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Text = apply { - if (validated) { - return@apply - } - - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -2814,7 +2889,18 @@ private constructor( * @throws IllegalStateException if any required field is unset. */ fun build(): Text = - Text(checkRequired("type", type), additionalProperties.toImmutable()) + Text(checkRequired("type", type), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Text = apply { + if (validated) { + return@apply + } + + type() + validated = true } class Type @@ -3187,20 +3273,23 @@ private constructor( override fun toString() = value.toString() } - @NoAutoDetect class Function - @JsonCreator private constructor( - @JsonProperty("function") - @ExcludeMissing - private val function: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val function: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("function") + @ExcludeMissing + function: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + ) : this(function, type, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type or is unexpectedly missing or null (e.g. if the server responded with @@ -3233,21 +3322,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Function = apply { - if (validated) { - return@apply - } - - function().validate() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -3343,22 +3426,35 @@ private constructor( Function( checkRequired("function", function), checkRequired("type", type), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } - @NoAutoDetect + private var validated: Boolean = false + + fun validate(): Function = apply { + if (validated) { + return@apply + } + + function().validate() + type() + validated = true + } + class InnerFunction - @JsonCreator private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = - immutableEmptyMap(), + private val name: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of() + ) : this(name, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an * unexpected type or is unexpectedly missing or null (e.g. if the server @@ -3374,20 +3470,15 @@ private constructor( */ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): InnerFunction = apply { - if (validated) { - return@apply - } - - name() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -3468,10 +3559,21 @@ private constructor( fun build(): InnerFunction = InnerFunction( checkRequired("name", name), - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): InnerFunction = apply { + if (validated) { + return@apply + } + + name() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3628,35 +3730,48 @@ private constructor( "OpenAIModelParams{frequencyPenalty=$frequencyPenalty, functionCall=$functionCall, maxCompletionTokens=$maxCompletionTokens, maxTokens=$maxTokens, n=$n, presencePenalty=$presencePenalty, reasoningEffort=$reasoningEffort, responseFormat=$responseFormat, stop=$stop, temperature=$temperature, toolChoice=$toolChoice, topP=$topP, useCache=$useCache, additionalProperties=$additionalProperties}" } - @NoAutoDetect class AnthropicModelParams - @JsonCreator private constructor( - @JsonProperty("max_tokens") - @ExcludeMissing - private val maxTokens: JsonField = JsonMissing.of(), - @JsonProperty("temperature") - @ExcludeMissing - private val temperature: JsonField = JsonMissing.of(), - @JsonProperty("max_tokens_to_sample") - @ExcludeMissing - private val maxTokensToSample: JsonField = JsonMissing.of(), - @JsonProperty("stop_sequences") - @ExcludeMissing - private val stopSequences: JsonField> = JsonMissing.of(), - @JsonProperty("top_k") - @ExcludeMissing - private val topK: JsonField = JsonMissing.of(), - @JsonProperty("top_p") - @ExcludeMissing - private val topP: JsonField = JsonMissing.of(), - @JsonProperty("use_cache") - @ExcludeMissing - private val useCache: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val maxTokens: JsonField, + private val temperature: JsonField, + private val maxTokensToSample: JsonField, + private val stopSequences: JsonField>, + private val topK: JsonField, + private val topP: JsonField, + private val useCache: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("max_tokens") + @ExcludeMissing + maxTokens: JsonField = JsonMissing.of(), + @JsonProperty("temperature") + @ExcludeMissing + temperature: JsonField = JsonMissing.of(), + @JsonProperty("max_tokens_to_sample") + @ExcludeMissing + maxTokensToSample: JsonField = JsonMissing.of(), + @JsonProperty("stop_sequences") + @ExcludeMissing + stopSequences: JsonField> = JsonMissing.of(), + @JsonProperty("top_k") @ExcludeMissing topK: JsonField = JsonMissing.of(), + @JsonProperty("top_p") @ExcludeMissing topP: JsonField = JsonMissing.of(), + @JsonProperty("use_cache") + @ExcludeMissing + useCache: JsonField = JsonMissing.of(), + ) : this( + maxTokens, + temperature, + maxTokensToSample, + stopSequences, + topK, + topP, + useCache, + mutableMapOf(), + ) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected @@ -3770,26 +3885,15 @@ private constructor( @ExcludeMissing fun _useCache(): JsonField = useCache + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): AnthropicModelParams = apply { - if (validated) { - return@apply - } - - maxTokens() - temperature() - maxTokensToSample() - stopSequences() - topK() - topP() - useCache() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -3973,10 +4077,27 @@ private constructor( topK, topP, useCache, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): AnthropicModelParams = apply { + if (validated) { + return@apply + } + + maxTokens() + temperature() + maxTokensToSample() + stopSequences() + topK() + topP() + useCache() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3995,29 +4116,31 @@ private constructor( "AnthropicModelParams{maxTokens=$maxTokens, temperature=$temperature, maxTokensToSample=$maxTokensToSample, stopSequences=$stopSequences, topK=$topK, topP=$topP, useCache=$useCache, additionalProperties=$additionalProperties}" } - @NoAutoDetect class GoogleModelParams - @JsonCreator private constructor( - @JsonProperty("maxOutputTokens") - @ExcludeMissing - private val maxOutputTokens: JsonField = JsonMissing.of(), - @JsonProperty("temperature") - @ExcludeMissing - private val temperature: JsonField = JsonMissing.of(), - @JsonProperty("topK") - @ExcludeMissing - private val topK: JsonField = JsonMissing.of(), - @JsonProperty("topP") - @ExcludeMissing - private val topP: JsonField = JsonMissing.of(), - @JsonProperty("use_cache") - @ExcludeMissing - private val useCache: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val maxOutputTokens: JsonField, + private val temperature: JsonField, + private val topK: JsonField, + private val topP: JsonField, + private val useCache: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("maxOutputTokens") + @ExcludeMissing + maxOutputTokens: JsonField = JsonMissing.of(), + @JsonProperty("temperature") + @ExcludeMissing + temperature: JsonField = JsonMissing.of(), + @JsonProperty("topK") @ExcludeMissing topK: JsonField = JsonMissing.of(), + @JsonProperty("topP") @ExcludeMissing topP: JsonField = JsonMissing.of(), + @JsonProperty("use_cache") + @ExcludeMissing + useCache: JsonField = JsonMissing.of(), + ) : this(maxOutputTokens, temperature, topK, topP, useCache, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). @@ -4095,24 +4218,15 @@ private constructor( @ExcludeMissing fun _useCache(): JsonField = useCache + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): GoogleModelParams = apply { - if (validated) { - return@apply - } - - maxOutputTokens() - temperature() - topK() - topP() - useCache() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -4238,10 +4352,25 @@ private constructor( topK, topP, useCache, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): GoogleModelParams = apply { + if (validated) { + return@apply + } + + maxOutputTokens() + temperature() + topK() + topP() + useCache() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -4260,23 +4389,25 @@ private constructor( "GoogleModelParams{maxOutputTokens=$maxOutputTokens, temperature=$temperature, topK=$topK, topP=$topP, useCache=$useCache, additionalProperties=$additionalProperties}" } - @NoAutoDetect class WindowAiModelParams - @JsonCreator private constructor( - @JsonProperty("temperature") - @ExcludeMissing - private val temperature: JsonField = JsonMissing.of(), - @JsonProperty("topK") - @ExcludeMissing - private val topK: JsonField = JsonMissing.of(), - @JsonProperty("use_cache") - @ExcludeMissing - private val useCache: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val temperature: JsonField, + private val topK: JsonField, + private val useCache: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("temperature") + @ExcludeMissing + temperature: JsonField = JsonMissing.of(), + @JsonProperty("topK") @ExcludeMissing topK: JsonField = JsonMissing.of(), + @JsonProperty("use_cache") + @ExcludeMissing + useCache: JsonField = JsonMissing.of(), + ) : this(temperature, topK, useCache, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). @@ -4324,22 +4455,15 @@ private constructor( @ExcludeMissing fun _useCache(): JsonField = useCache + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): WindowAiModelParams = apply { - if (validated) { - return@apply - } - - temperature() - topK() - useCache() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -4434,10 +4558,23 @@ private constructor( temperature, topK, useCache, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): WindowAiModelParams = apply { + if (validated) { + return@apply + } + + temperature() + topK() + useCache() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -4456,17 +4593,19 @@ private constructor( "WindowAiModelParams{temperature=$temperature, topK=$topK, useCache=$useCache, additionalProperties=$additionalProperties}" } - @NoAutoDetect class JsCompletionParams - @JsonCreator private constructor( - @JsonProperty("use_cache") - @ExcludeMissing - private val useCache: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val useCache: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("use_cache") + @ExcludeMissing + useCache: JsonField = JsonMissing.of() + ) : this(useCache, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). @@ -4484,20 +4623,15 @@ private constructor( @ExcludeMissing fun _useCache(): JsonField = useCache + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): JsCompletionParams = apply { - if (validated) { - return@apply - } - - useCache() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -4560,7 +4694,18 @@ private constructor( * Further updates to this [Builder] will not mutate the returned instance. */ fun build(): JsCompletionParams = - JsCompletionParams(useCache, additionalProperties.toImmutable()) + JsCompletionParams(useCache, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): JsCompletionParams = apply { + if (validated) { + return@apply + } + + useCache() + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptReplaceParams.kt index 7521b155..5039be57 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptReplaceParams.kt @@ -7,19 +7,18 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -144,401 +143,261 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams + fun toBuilder() = Builder().from(this) - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("project_id") - @ExcludeMissing - private val projectId: JsonField = JsonMissing.of(), - @JsonProperty("slug") - @ExcludeMissing - private val slug: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("function_type") - @ExcludeMissing - private val functionType: JsonField = JsonMissing.of(), - @JsonProperty("prompt_data") - @ExcludeMissing - private val promptData: JsonField = JsonMissing.of(), - @JsonProperty("tags") - @ExcludeMissing - private val tags: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + companion object { /** - * Name of the prompt + * Returns a mutable builder for constructing an instance of [PromptReplaceParams]. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + * The following fields are required: + * ```java + * .name() + * .projectId() + * .slug() + * ``` */ - fun name(): String = name.getRequired("name") + @JvmStatic fun builder() = Builder() + } - /** - * Unique identifier for the project that the prompt belongs under - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun projectId(): String = projectId.getRequired("project_id") + /** A builder for [PromptReplaceParams]. */ + class Builder internal constructor() { - /** - * Unique identifier for the prompt - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun slug(): String = slug.getRequired("slug") + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - /** - * Textual description of the prompt - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + @JvmSynthetic + internal fun from(promptReplaceParams: PromptReplaceParams) = apply { + body = promptReplaceParams.body.toBuilder() + additionalHeaders = promptReplaceParams.additionalHeaders.toBuilder() + additionalQueryParams = promptReplaceParams.additionalQueryParams.toBuilder() + } - /** - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun functionType(): Optional = - Optional.ofNullable(functionType.getNullable("function_type")) + /** Name of the prompt */ + fun name(name: String) = apply { body.name(name) } /** - * The prompt, model, and its parameters + * Sets [Builder.name] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun promptData(): Optional = - Optional.ofNullable(promptData.getNullable("prompt_data")) + fun name(name: JsonField) = apply { body.name(name) } - /** - * A list of tags for the prompt - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) + /** Unique identifier for the project that the prompt belongs under */ + fun projectId(projectId: String) = apply { body.projectId(projectId) } /** - * Returns the raw JSON value of [name]. + * Sets [Builder.projectId] to an arbitrary JSON value. * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.projectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + fun projectId(projectId: JsonField) = apply { body.projectId(projectId) } + + /** Unique identifier for the prompt */ + fun slug(slug: String) = apply { body.slug(slug) } /** - * Returns the raw JSON value of [projectId]. + * Sets [Builder.slug] to an arbitrary JSON value. * - * Unlike [projectId], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.slug] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("project_id") @ExcludeMissing fun _projectId(): JsonField = projectId + fun slug(slug: JsonField) = apply { body.slug(slug) } + + /** Textual description of the prompt */ + fun description(description: String?) = apply { body.description(description) } + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) /** - * Returns the raw JSON value of [slug]. + * Sets [Builder.description] to an arbitrary JSON value. * - * Unlike [slug], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("slug") @ExcludeMissing fun _slug(): JsonField = slug + fun description(description: JsonField) = apply { body.description(description) } + + fun functionType(functionType: FunctionType?) = apply { body.functionType(functionType) } + + /** Alias for calling [Builder.functionType] with `functionType.orElse(null)`. */ + fun functionType(functionType: Optional) = + functionType(functionType.getOrNull()) /** - * Returns the raw JSON value of [description]. + * Sets [Builder.functionType] to an arbitrary JSON value. * - * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.functionType] with a well-typed [FunctionType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("description") - @ExcludeMissing - fun _description(): JsonField = description + fun functionType(functionType: JsonField) = apply { + body.functionType(functionType) + } + + /** The prompt, model, and its parameters */ + fun promptData(promptData: PromptData?) = apply { body.promptData(promptData) } + + /** Alias for calling [Builder.promptData] with `promptData.orElse(null)`. */ + fun promptData(promptData: Optional) = promptData(promptData.getOrNull()) /** - * Returns the raw JSON value of [functionType]. + * Sets [Builder.promptData] to an arbitrary JSON value. * - * Unlike [functionType], this method doesn't throw if the JSON field has an unexpected - * type. + * You should usually call [Builder.promptData] with a well-typed [PromptData] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("function_type") - @ExcludeMissing - fun _functionType(): JsonField = functionType + fun promptData(promptData: JsonField) = apply { body.promptData(promptData) } + + /** A list of tags for the prompt */ + fun tags(tags: List?) = apply { body.tags(tags) } + + /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ + fun tags(tags: Optional>) = tags(tags.getOrNull()) /** - * Returns the raw JSON value of [promptData]. + * Sets [Builder.tags] to an arbitrary JSON value. * - * Unlike [promptData], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.tags] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("prompt_data") - @ExcludeMissing - fun _promptData(): JsonField = promptData + fun tags(tags: JsonField>) = apply { body.tags(tags) } /** - * Returns the raw JSON value of [tags]. + * Adds a single [String] to [tags]. * - * Unlike [tags], this method doesn't throw if the JSON field has an unexpected type. + * @throws IllegalStateException if the field was previously set to a non-list. */ - @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags + fun addTag(tag: String) = apply { body.addTag(tag) } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } - private var validated: Boolean = false + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } - fun validate(): Body = apply { - if (validated) { - return@apply + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) } - name() - projectId() - slug() - description() - functionType() - promptData().ifPresent { it.validate() } - tags() - validated = true + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) } - fun toBuilder() = Builder().from(this) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - companion object { + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .name() - * .projectId() - * .slug() - * ``` - */ - @JvmStatic fun builder() = Builder() + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - /** A builder for [Body]. */ - class Builder internal constructor() { + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - private var name: JsonField? = null - private var projectId: JsonField? = null - private var slug: JsonField? = null - private var description: JsonField = JsonMissing.of() - private var functionType: JsonField = JsonMissing.of() - private var promptData: JsonField = JsonMissing.of() - private var tags: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - @JvmSynthetic - internal fun from(body: Body) = apply { - name = body.name - projectId = body.projectId - slug = body.slug - description = body.description - functionType = body.functionType - promptData = body.promptData - tags = body.tags.map { it.toMutableList() } - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** Name of the prompt */ - fun name(name: String) = name(JsonField.of(name)) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } - - /** Unique identifier for the project that the prompt belongs under */ - fun projectId(projectId: String) = projectId(JsonField.of(projectId)) - - /** - * Sets [Builder.projectId] to an arbitrary JSON value. - * - * You should usually call [Builder.projectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun projectId(projectId: JsonField) = apply { this.projectId = projectId } - - /** Unique identifier for the prompt */ - fun slug(slug: String) = slug(JsonField.of(slug)) - - /** - * Sets [Builder.slug] to an arbitrary JSON value. - * - * You should usually call [Builder.slug] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun slug(slug: JsonField) = apply { this.slug = slug } - - /** Textual description of the prompt */ - fun description(description: String?) = description(JsonField.ofNullable(description)) - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) - - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun description(description: JsonField) = apply { - this.description = description - } - - fun functionType(functionType: FunctionType?) = - functionType(JsonField.ofNullable(functionType)) - - /** Alias for calling [Builder.functionType] with `functionType.orElse(null)`. */ - fun functionType(functionType: Optional) = - functionType(functionType.getOrNull()) - - /** - * Sets [Builder.functionType] to an arbitrary JSON value. - * - * You should usually call [Builder.functionType] with a well-typed [FunctionType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun functionType(functionType: JsonField) = apply { - this.functionType = functionType - } - - /** The prompt, model, and its parameters */ - fun promptData(promptData: PromptData?) = promptData(JsonField.ofNullable(promptData)) - - /** Alias for calling [Builder.promptData] with `promptData.orElse(null)`. */ - fun promptData(promptData: Optional) = promptData(promptData.getOrNull()) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** - * Sets [Builder.promptData] to an arbitrary JSON value. - * - * You should usually call [Builder.promptData] with a well-typed [PromptData] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun promptData(promptData: JsonField) = apply { - this.promptData = promptData - } + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - /** A list of tags for the prompt */ - fun tags(tags: List?) = tags(JsonField.ofNullable(tags)) + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ - fun tags(tags: Optional>) = tags(tags.getOrNull()) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Sets [Builder.tags] to an arbitrary JSON value. - * - * You should usually call [Builder.tags] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun tags(tags: JsonField>) = apply { - this.tags = tags.map { it.toMutableList() } - } + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Adds a single [String] to [tags]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addTag(tag: String) = apply { - tags = - (tags ?: JsonField.of(mutableListOf())).also { checkKnown("tags", it).add(tag) } - } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * .projectId() - * .slug() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("name", name), - checkRequired("projectId", projectId), - checkRequired("slug", slug), - description, - functionType, - promptData, - (tags ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), - ) + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - return /* spotless:off */ other is Body && name == other.name && projectId == other.projectId && slug == other.slug && description == other.description && functionType == other.functionType && promptData == other.promptData && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, projectId, slug, description, functionType, promptData, tags, additionalProperties) } - /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } - override fun hashCode(): Int = hashCode + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - override fun toString() = - "Body{name=$name, projectId=$projectId, slug=$slug, description=$description, functionType=$functionType, promptData=$promptData, tags=$tags, additionalProperties=$additionalProperties}" - } + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - fun toBuilder() = Builder().from(this) + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - companion object { + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } /** - * Returns a mutable builder for constructing an instance of [PromptReplaceParams]. + * Returns an immutable instance of [PromptReplaceParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java @@ -546,265 +405,412 @@ private constructor( * .projectId() * .slug() * ``` + * + * @throws IllegalStateException if any required field is unset. */ - @JvmStatic fun builder() = Builder() + fun build(): PromptReplaceParams = + PromptReplaceParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) } - /** A builder for [PromptReplaceParams]. */ - @NoAutoDetect - class Builder internal constructor() { + @JvmSynthetic internal fun _body(): Body = body - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun from(promptReplaceParams: PromptReplaceParams) = apply { - body = promptReplaceParams.body.toBuilder() - additionalHeaders = promptReplaceParams.additionalHeaders.toBuilder() - additionalQueryParams = promptReplaceParams.additionalQueryParams.toBuilder() - } + override fun _queryParams(): QueryParams = additionalQueryParams - /** Name of the prompt */ - fun name(name: String) = apply { body.name(name) } + class Body + private constructor( + private val name: JsonField, + private val projectId: JsonField, + private val slug: JsonField, + private val description: JsonField, + private val functionType: JsonField, + private val promptData: JsonField, + private val tags: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("slug") @ExcludeMissing slug: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("function_type") + @ExcludeMissing + functionType: JsonField = JsonMissing.of(), + @JsonProperty("prompt_data") + @ExcludeMissing + promptData: JsonField = JsonMissing.of(), + @JsonProperty("tags") @ExcludeMissing tags: JsonField> = JsonMissing.of(), + ) : this(name, projectId, slug, description, functionType, promptData, tags, mutableMapOf()) /** - * Sets [Builder.name] to an arbitrary JSON value. + * Name of the prompt * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun name(name: JsonField) = apply { body.name(name) } - - /** Unique identifier for the project that the prompt belongs under */ - fun projectId(projectId: String) = apply { body.projectId(projectId) } + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") /** - * Sets [Builder.projectId] to an arbitrary JSON value. + * Unique identifier for the project that the prompt belongs under * - * You should usually call [Builder.projectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun projectId(projectId: JsonField) = apply { body.projectId(projectId) } - - /** Unique identifier for the prompt */ - fun slug(slug: String) = apply { body.slug(slug) } + fun projectId(): String = projectId.getRequired("project_id") /** - * Sets [Builder.slug] to an arbitrary JSON value. + * Unique identifier for the prompt * - * You should usually call [Builder.slug] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun slug(slug: JsonField) = apply { body.slug(slug) } - - /** Textual description of the prompt */ - fun description(description: String?) = apply { body.description(description) } - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) + fun slug(): String = slug.getRequired("slug") /** - * Sets [Builder.description] to an arbitrary JSON value. + * Textual description of the prompt * - * You should usually call [Builder.description] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun description(description: JsonField) = apply { body.description(description) } + fun description(): Optional = + Optional.ofNullable(description.getNullable("description")) - fun functionType(functionType: FunctionType?) = apply { body.functionType(functionType) } + /** + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun functionType(): Optional = + Optional.ofNullable(functionType.getNullable("function_type")) - /** Alias for calling [Builder.functionType] with `functionType.orElse(null)`. */ - fun functionType(functionType: Optional) = - functionType(functionType.getOrNull()) + /** + * The prompt, model, and its parameters + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun promptData(): Optional = + Optional.ofNullable(promptData.getNullable("prompt_data")) /** - * Sets [Builder.functionType] to an arbitrary JSON value. + * A list of tags for the prompt * - * You should usually call [Builder.functionType] with a well-typed [FunctionType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun functionType(functionType: JsonField) = apply { - body.functionType(functionType) - } + fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) - /** The prompt, model, and its parameters */ - fun promptData(promptData: PromptData?) = apply { body.promptData(promptData) } + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - /** Alias for calling [Builder.promptData] with `promptData.orElse(null)`. */ - fun promptData(promptData: Optional) = promptData(promptData.getOrNull()) + /** + * Returns the raw JSON value of [projectId]. + * + * Unlike [projectId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("project_id") @ExcludeMissing fun _projectId(): JsonField = projectId /** - * Sets [Builder.promptData] to an arbitrary JSON value. + * Returns the raw JSON value of [slug]. * - * You should usually call [Builder.promptData] with a well-typed [PromptData] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * Unlike [slug], this method doesn't throw if the JSON field has an unexpected type. */ - fun promptData(promptData: JsonField) = apply { body.promptData(promptData) } + @JsonProperty("slug") @ExcludeMissing fun _slug(): JsonField = slug - /** A list of tags for the prompt */ - fun tags(tags: List?) = apply { body.tags(tags) } + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description - /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ - fun tags(tags: Optional>) = tags(tags.getOrNull()) + /** + * Returns the raw JSON value of [functionType]. + * + * Unlike [functionType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("function_type") + @ExcludeMissing + fun _functionType(): JsonField = functionType /** - * Sets [Builder.tags] to an arbitrary JSON value. + * Returns the raw JSON value of [promptData]. * - * You should usually call [Builder.tags] with a well-typed `List` value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [promptData], this method doesn't throw if the JSON field has an unexpected type. */ - fun tags(tags: JsonField>) = apply { body.tags(tags) } + @JsonProperty("prompt_data") + @ExcludeMissing + fun _promptData(): JsonField = promptData /** - * Adds a single [String] to [tags]. + * Returns the raw JSON value of [tags]. * - * @throws IllegalStateException if the field was previously set to a non-list. + * Unlike [tags], this method doesn't throw if the JSON field has an unexpected type. */ - fun addTag(tag: String) = apply { body.addTag(tag) } + @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .name() + * .projectId() + * .slug() + * ``` + */ + @JvmStatic fun builder() = Builder() } - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var name: JsonField? = null + private var projectId: JsonField? = null + private var slug: JsonField? = null + private var description: JsonField = JsonMissing.of() + private var functionType: JsonField = JsonMissing.of() + private var promptData: JsonField = JsonMissing.of() + private var tags: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + name = body.name + projectId = body.projectId + slug = body.slug + description = body.description + functionType = body.functionType + promptData = body.promptData + tags = body.tags.map { it.toMutableList() } + additionalProperties = body.additionalProperties.toMutableMap() } - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + /** Name of the prompt */ + fun name(name: String) = name(JsonField.of(name)) - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** Unique identifier for the project that the prompt belongs under */ + fun projectId(projectId: String) = projectId(JsonField.of(projectId)) - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * Sets [Builder.projectId] to an arbitrary JSON value. + * + * You should usually call [Builder.projectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun projectId(projectId: JsonField) = apply { this.projectId = projectId } - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } + /** Unique identifier for the prompt */ + fun slug(slug: String) = slug(JsonField.of(slug)) - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } + /** + * Sets [Builder.slug] to an arbitrary JSON value. + * + * You should usually call [Builder.slug] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun slug(slug: JsonField) = apply { this.slug = slug } - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** Textual description of the prompt */ + fun description(description: String?) = description(JsonField.ofNullable(description)) - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } + fun functionType(functionType: FunctionType?) = + functionType(JsonField.ofNullable(functionType)) - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** Alias for calling [Builder.functionType] with `functionType.orElse(null)`. */ + fun functionType(functionType: Optional) = + functionType(functionType.getOrNull()) - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** + * Sets [Builder.functionType] to an arbitrary JSON value. + * + * You should usually call [Builder.functionType] with a well-typed [FunctionType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun functionType(functionType: JsonField) = apply { + this.functionType = functionType + } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + /** The prompt, model, and its parameters */ + fun promptData(promptData: PromptData?) = promptData(JsonField.ofNullable(promptData)) - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } + /** Alias for calling [Builder.promptData] with `promptData.orElse(null)`. */ + fun promptData(promptData: Optional) = promptData(promptData.getOrNull()) - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + /** + * Sets [Builder.promptData] to an arbitrary JSON value. + * + * You should usually call [Builder.promptData] with a well-typed [PromptData] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun promptData(promptData: JsonField) = apply { + this.promptData = promptData + } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + /** A list of tags for the prompt */ + fun tags(tags: List?) = tags(JsonField.ofNullable(tags)) - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } + /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ + fun tags(tags: Optional>) = tags(tags.getOrNull()) - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) - } + /** + * Sets [Builder.tags] to an arbitrary JSON value. + * + * You should usually call [Builder.tags] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tags(tags: JsonField>) = apply { + this.tags = tags.map { it.toMutableList() } + } - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } + /** + * Adds a single [String] to [tags]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTag(tag: String) = apply { + tags = + (tags ?: JsonField.of(mutableListOf())).also { checkKnown("tags", it).add(tag) } + } - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) } - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * .projectId() + * .slug() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("name", name), + checkRequired("projectId", projectId), + checkRequired("slug", slug), + description, + functionType, + promptData, + (tags ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply } - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + name() + projectId() + slug() + description() + functionType() + promptData().ifPresent { it.validate() } + tags() + validated = true + } - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && name == other.name && projectId == other.projectId && slug == other.slug && description == other.description && functionType == other.functionType && promptData == other.promptData && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ } - /** - * Returns an immutable instance of [PromptReplaceParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * .projectId() - * .slug() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): PromptReplaceParams = - PromptReplaceParams( - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(name, projectId, slug, description, functionType, promptData, tags, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{name=$name, projectId=$projectId, slug=$slug, description=$description, functionType=$functionType, promptData=$promptData, tags=$tags, additionalProperties=$additionalProperties}" } class FunctionType @JsonCreator private constructor(private val value: JsonField) : diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptRetrieveParams.kt index 382c2b86..b05a03df 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptRetrieveParams.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers @@ -24,16 +23,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _pathParam(index: Int): String = - when (index) { - 0 -> promptId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - fun toBuilder() = Builder().from(this) companion object { @@ -50,7 +39,6 @@ private constructor( } /** A builder for [PromptRetrieveParams]. */ - @NoAutoDetect class Builder internal constructor() { private var promptId: String? = null @@ -185,6 +173,16 @@ private constructor( ) } + fun _pathParam(index: Int): String = + when (index) { + 0 -> promptId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt index 8a98d6da..bfd3b27e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt @@ -6,19 +6,18 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -120,200 +119,443 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body + fun toBuilder() = Builder().from(this) - fun _pathParam(index: Int): String = - when (index) { - 0 -> promptId - else -> "" + companion object { + + /** + * Returns a mutable builder for constructing an instance of [PromptUpdateParams]. + * + * The following fields are required: + * ```java + * .promptId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PromptUpdateParams]. */ + class Builder internal constructor() { + + private var promptId: String? = null + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(promptUpdateParams: PromptUpdateParams) = apply { + promptId = promptUpdateParams.promptId + body = promptUpdateParams.body.toBuilder() + additionalHeaders = promptUpdateParams.additionalHeaders.toBuilder() + additionalQueryParams = promptUpdateParams.additionalQueryParams.toBuilder() } - override fun _headers(): Headers = additionalHeaders + /** Prompt id */ + fun promptId(promptId: String) = apply { this.promptId = promptId } - override fun _queryParams(): QueryParams = additionalQueryParams + /** Textual description of the prompt */ + fun description(description: String?) = apply { body.description(description) } - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("prompt_data") - @ExcludeMissing - private val promptData: JsonField = JsonMissing.of(), - @JsonProperty("slug") - @ExcludeMissing - private val slug: JsonField = JsonMissing.of(), - @JsonProperty("tags") - @ExcludeMissing - private val tags: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) /** - * Textual description of the prompt + * Sets [Builder.description] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(description: JsonField) = apply { body.description(description) } - /** - * Name of the prompt - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + /** Name of the prompt */ + fun name(name: String?) = apply { body.name(name) } - /** - * The prompt, model, and its parameters - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun promptData(): Optional = - Optional.ofNullable(promptData.getNullable("prompt_data")) + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) /** - * Unique identifier for the prompt + * Sets [Builder.name] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun slug(): Optional = Optional.ofNullable(slug.getNullable("slug")) + fun name(name: JsonField) = apply { body.name(name) } - /** - * A list of tags for the prompt - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) + /** The prompt, model, and its parameters */ + fun promptData(promptData: PromptData?) = apply { body.promptData(promptData) } - /** - * Returns the raw JSON value of [description]. - * - * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("description") - @ExcludeMissing - fun _description(): JsonField = description + /** Alias for calling [Builder.promptData] with `promptData.orElse(null)`. */ + fun promptData(promptData: Optional) = promptData(promptData.getOrNull()) /** - * Returns the raw JSON value of [name]. + * Sets [Builder.promptData] to an arbitrary JSON value. * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.promptData] with a well-typed [PromptData] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + fun promptData(promptData: JsonField) = apply { body.promptData(promptData) } + + /** Unique identifier for the prompt */ + fun slug(slug: String?) = apply { body.slug(slug) } + + /** Alias for calling [Builder.slug] with `slug.orElse(null)`. */ + fun slug(slug: Optional) = slug(slug.getOrNull()) /** - * Returns the raw JSON value of [promptData]. + * Sets [Builder.slug] to an arbitrary JSON value. * - * Unlike [promptData], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.slug] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("prompt_data") - @ExcludeMissing - fun _promptData(): JsonField = promptData + fun slug(slug: JsonField) = apply { body.slug(slug) } + + /** A list of tags for the prompt */ + fun tags(tags: List?) = apply { body.tags(tags) } + + /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ + fun tags(tags: Optional>) = tags(tags.getOrNull()) /** - * Returns the raw JSON value of [slug]. + * Sets [Builder.tags] to an arbitrary JSON value. * - * Unlike [slug], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.tags] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("slug") @ExcludeMissing fun _slug(): JsonField = slug + fun tags(tags: JsonField>) = apply { body.tags(tags) } /** - * Returns the raw JSON value of [tags]. + * Adds a single [String] to [tags]. * - * Unlike [tags], this method doesn't throw if the JSON field has an unexpected type. + * @throws IllegalStateException if the field was previously set to a non-list. */ - @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags + fun addTag(tag: String) = apply { body.addTag(tag) } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } - private var validated: Boolean = false + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } - fun validate(): Body = apply { - if (validated) { - return@apply + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) } - description() - name() - promptData().ifPresent { it.validate() } - slug() - tags() - validated = true - } + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - fun toBuilder() = Builder().from(this) + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } - companion object { + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** Returns a mutable builder for constructing an instance of [Body]. */ - @JvmStatic fun builder() = Builder() + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - /** A builder for [Body]. */ - class Builder internal constructor() { + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } - private var description: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var promptData: JsonField = JsonMissing.of() - private var slug: JsonField = JsonMissing.of() - private var tags: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - @JvmSynthetic - internal fun from(body: Body) = apply { - description = body.description - name = body.name - promptData = body.promptData - slug = body.slug - tags = body.tags.map { it.toMutableList() } - additionalProperties = body.additionalProperties.toMutableMap() - } + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** Textual description of the prompt */ - fun description(description: String?) = description(JsonField.ofNullable(description)) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun description(description: JsonField) = apply { - this.description = description - } + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** Name of the prompt */ - fun name(name: String?) = name(JsonField.ofNullable(name)) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** Alias for calling [Builder.name] with `name.orElse(null)`. */ - fun name(name: Optional) = name(name.getOrNull()) + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } + 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) + } + + /** + * Returns an immutable instance of [PromptUpdateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .promptId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PromptUpdateParams = + PromptUpdateParams( + checkRequired("promptId", promptId), + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + @JvmSynthetic internal fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> promptId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val description: JsonField, + private val name: JsonField, + private val promptData: JsonField, + private val slug: JsonField, + private val tags: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("prompt_data") + @ExcludeMissing + promptData: JsonField = JsonMissing.of(), + @JsonProperty("slug") @ExcludeMissing slug: JsonField = JsonMissing.of(), + @JsonProperty("tags") @ExcludeMissing tags: JsonField> = JsonMissing.of(), + ) : this(description, name, promptData, slug, tags, mutableMapOf()) + + /** + * Textual description of the prompt + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun description(): Optional = + Optional.ofNullable(description.getNullable("description")) + + /** + * Name of the prompt + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + /** + * The prompt, model, and its parameters + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun promptData(): Optional = + Optional.ofNullable(promptData.getNullable("prompt_data")) + + /** + * Unique identifier for the prompt + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun slug(): Optional = Optional.ofNullable(slug.getNullable("slug")) + + /** + * A list of tags for the prompt + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [promptData]. + * + * Unlike [promptData], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("prompt_data") + @ExcludeMissing + fun _promptData(): JsonField = promptData + + /** + * Returns the raw JSON value of [slug]. + * + * Unlike [slug], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("slug") @ExcludeMissing fun _slug(): JsonField = slug + + /** + * Returns the raw JSON value of [tags]. + * + * Unlike [tags], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tags") @ExcludeMissing fun _tags(): JsonField> = tags + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Body]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var description: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var promptData: JsonField = JsonMissing.of() + private var slug: JsonField = JsonMissing.of() + private var tags: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + description = body.description + name = body.name + promptData = body.promptData + slug = body.slug + tags = body.tags.map { it.toMutableList() } + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** Textual description of the prompt */ + fun description(description: String?) = description(JsonField.ofNullable(description)) + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } + + /** Name of the prompt */ + fun name(name: String?) = name(JsonField.ofNullable(name)) + + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } /** The prompt, model, and its parameters */ fun promptData(promptData: PromptData?) = promptData(JsonField.ofNullable(promptData)) @@ -405,10 +647,25 @@ private constructor( promptData, slug, (tags ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + description() + name() + promptData().ifPresent { it.validate() } + slug() + tags() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -427,259 +684,6 @@ private constructor( "Body{description=$description, name=$name, promptData=$promptData, slug=$slug, tags=$tags, additionalProperties=$additionalProperties}" } - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [PromptUpdateParams]. - * - * The following fields are required: - * ```java - * .promptId() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [PromptUpdateParams]. */ - @NoAutoDetect - class Builder internal constructor() { - - private var promptId: String? = null - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - - @JvmSynthetic - internal fun from(promptUpdateParams: PromptUpdateParams) = apply { - promptId = promptUpdateParams.promptId - body = promptUpdateParams.body.toBuilder() - additionalHeaders = promptUpdateParams.additionalHeaders.toBuilder() - additionalQueryParams = promptUpdateParams.additionalQueryParams.toBuilder() - } - - /** Prompt id */ - fun promptId(promptId: String) = apply { this.promptId = promptId } - - /** Textual description of the prompt */ - fun description(description: String?) = apply { body.description(description) } - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) - - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun description(description: JsonField) = apply { body.description(description) } - - /** Name of the prompt */ - fun name(name: String?) = apply { body.name(name) } - - /** Alias for calling [Builder.name] with `name.orElse(null)`. */ - fun name(name: Optional) = name(name.getOrNull()) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun name(name: JsonField) = apply { body.name(name) } - - /** The prompt, model, and its parameters */ - fun promptData(promptData: PromptData?) = apply { body.promptData(promptData) } - - /** Alias for calling [Builder.promptData] with `promptData.orElse(null)`. */ - fun promptData(promptData: Optional) = promptData(promptData.getOrNull()) - - /** - * Sets [Builder.promptData] to an arbitrary JSON value. - * - * You should usually call [Builder.promptData] with a well-typed [PromptData] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun promptData(promptData: JsonField) = apply { body.promptData(promptData) } - - /** Unique identifier for the prompt */ - fun slug(slug: String?) = apply { body.slug(slug) } - - /** Alias for calling [Builder.slug] with `slug.orElse(null)`. */ - fun slug(slug: Optional) = slug(slug.getOrNull()) - - /** - * Sets [Builder.slug] to an arbitrary JSON value. - * - * You should usually call [Builder.slug] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun slug(slug: JsonField) = apply { body.slug(slug) } - - /** A list of tags for the prompt */ - fun tags(tags: List?) = apply { body.tags(tags) } - - /** Alias for calling [Builder.tags] with `tags.orElse(null)`. */ - fun tags(tags: Optional>) = tags(tags.getOrNull()) - - /** - * Sets [Builder.tags] to an arbitrary JSON value. - * - * You should usually call [Builder.tags] with a well-typed `List` value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun tags(tags: JsonField>) = apply { body.tags(tags) } - - /** - * Adds a single [String] to [tags]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addTag(tag: String) = apply { body.addTag(tag) } - - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) - } - - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } - - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) - } - - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } - - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } - - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } - - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(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 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) - } - - /** - * Returns an immutable instance of [PromptUpdateParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .promptId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): PromptUpdateParams = - PromptUpdateParams( - checkRequired("promptId", promptId), - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RepoInfo.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RepoInfo.kt index 0ce351bc..a6081b97 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RepoInfo.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RepoInfo.kt @@ -6,49 +6,63 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Metadata about the state of the repo when the experiment was created */ -@NoAutoDetect class RepoInfo -@JsonCreator private constructor( - @JsonProperty("author_email") - @ExcludeMissing - private val authorEmail: JsonField = JsonMissing.of(), - @JsonProperty("author_name") - @ExcludeMissing - private val authorName: JsonField = JsonMissing.of(), - @JsonProperty("branch") - @ExcludeMissing - private val branch: JsonField = JsonMissing.of(), - @JsonProperty("commit") - @ExcludeMissing - private val commit: JsonField = JsonMissing.of(), - @JsonProperty("commit_message") - @ExcludeMissing - private val commitMessage: JsonField = JsonMissing.of(), - @JsonProperty("commit_time") - @ExcludeMissing - private val commitTime: JsonField = JsonMissing.of(), - @JsonProperty("dirty") @ExcludeMissing private val dirty: JsonField = JsonMissing.of(), - @JsonProperty("git_diff") - @ExcludeMissing - private val gitDiff: JsonField = JsonMissing.of(), - @JsonProperty("tag") @ExcludeMissing private val tag: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val authorEmail: JsonField, + private val authorName: JsonField, + private val branch: JsonField, + private val commit: JsonField, + private val commitMessage: JsonField, + private val commitTime: JsonField, + private val dirty: JsonField, + private val gitDiff: JsonField, + private val tag: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("author_email") + @ExcludeMissing + authorEmail: JsonField = JsonMissing.of(), + @JsonProperty("author_name") + @ExcludeMissing + authorName: JsonField = JsonMissing.of(), + @JsonProperty("branch") @ExcludeMissing branch: JsonField = JsonMissing.of(), + @JsonProperty("commit") @ExcludeMissing commit: JsonField = JsonMissing.of(), + @JsonProperty("commit_message") + @ExcludeMissing + commitMessage: JsonField = JsonMissing.of(), + @JsonProperty("commit_time") + @ExcludeMissing + commitTime: JsonField = JsonMissing.of(), + @JsonProperty("dirty") @ExcludeMissing dirty: JsonField = JsonMissing.of(), + @JsonProperty("git_diff") @ExcludeMissing gitDiff: JsonField = JsonMissing.of(), + @JsonProperty("tag") @ExcludeMissing tag: JsonField = JsonMissing.of(), + ) : this( + authorEmail, + authorName, + branch, + commit, + commitMessage, + commitTime, + dirty, + gitDiff, + tag, + mutableMapOf(), + ) + /** * Email of the author of the most recent commit * @@ -191,28 +205,15 @@ private constructor( */ @JsonProperty("tag") @ExcludeMissing fun _tag(): JsonField = tag + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): RepoInfo = apply { - if (validated) { - return@apply - } - - authorEmail() - authorName() - branch() - commit() - commitMessage() - commitTime() - dirty() - gitDiff() - tag() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -429,10 +430,29 @@ private constructor( dirty, gitDiff, tag, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): RepoInfo = apply { + if (validated) { + return@apply + } + + authorEmail() + authorName() + branch() + commit() + commitMessage() + commitTime() + dirty() + gitDiff() + tag() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Role.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Role.kt index 43105f4e..c9c1c582 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Role.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Role.kt @@ -6,10 +6,8 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter @@ -17,6 +15,7 @@ import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -26,34 +25,54 @@ import kotlin.jvm.optionals.getOrNull * * Roles can consist of individual permissions, as well as a set of roles they inherit from */ -@NoAutoDetect class Role -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing private val name: JsonField = JsonMissing.of(), - @JsonProperty("created") - @ExcludeMissing - private val created: JsonField = JsonMissing.of(), - @JsonProperty("deleted_at") - @ExcludeMissing - private val deletedAt: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("member_permissions") - @ExcludeMissing - private val memberPermissions: JsonField> = JsonMissing.of(), - @JsonProperty("member_roles") - @ExcludeMissing - private val memberRoles: JsonField> = JsonMissing.of(), - @JsonProperty("org_id") @ExcludeMissing private val orgId: JsonField = JsonMissing.of(), - @JsonProperty("user_id") - @ExcludeMissing - private val userId: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val name: JsonField, + private val created: JsonField, + private val deletedAt: JsonField, + private val description: JsonField, + private val memberPermissions: JsonField>, + private val memberRoles: JsonField>, + private val orgId: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("created") + @ExcludeMissing + created: JsonField = JsonMissing.of(), + @JsonProperty("deleted_at") + @ExcludeMissing + deletedAt: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("member_permissions") + @ExcludeMissing + memberPermissions: JsonField> = JsonMissing.of(), + @JsonProperty("member_roles") + @ExcludeMissing + memberRoles: JsonField> = JsonMissing.of(), + @JsonProperty("org_id") @ExcludeMissing orgId: JsonField = JsonMissing.of(), + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), + ) : this( + id, + name, + created, + deletedAt, + description, + memberPermissions, + memberRoles, + orgId, + userId, + mutableMapOf(), + ) + /** * Unique identifier for the role * @@ -208,28 +227,15 @@ private constructor( */ @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Role = apply { - if (validated) { - return@apply - } - - id() - name() - created() - deletedAt() - description() - memberPermissions().ifPresent { it.forEach { it.validate() } } - memberRoles() - orgId() - userId() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -485,24 +491,46 @@ private constructor( (memberRoles ?: JsonMissing.of()).map { it.toImmutable() }, orgId, userId, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } - @NoAutoDetect + private var validated: Boolean = false + + fun validate(): Role = apply { + if (validated) { + return@apply + } + + id() + name() + created() + deletedAt() + description() + memberPermissions().ifPresent { it.forEach { it.validate() } } + memberRoles() + orgId() + userId() + validated = true + } + class MemberPermission - @JsonCreator private constructor( - @JsonProperty("permission") - @ExcludeMissing - private val permission: JsonField = JsonMissing.of(), - @JsonProperty("restrict_object_type") - @ExcludeMissing - private val restrictObjectType: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val permission: JsonField, + private val restrictObjectType: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("permission") + @ExcludeMissing + permission: JsonField = JsonMissing.of(), + @JsonProperty("restrict_object_type") + @ExcludeMissing + restrictObjectType: JsonField = JsonMissing.of(), + ) : this(permission, restrictObjectType, mutableMapOf()) + /** * Each permission permits a certain type of operation on an object in the system * @@ -541,21 +569,15 @@ private constructor( @ExcludeMissing fun _restrictObjectType(): JsonField = restrictObjectType + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): MemberPermission = apply { - if (validated) { - return@apply - } - - permission() - restrictObjectType() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -662,10 +684,22 @@ private constructor( MemberPermission( checkRequired("permission", permission), restrictObjectType, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): MemberPermission = apply { + if (validated) { + return@apply + } + + permission() + restrictObjectType() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleCreateParams.kt index d33aa0b9..c90a6954 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleCreateParams.kt @@ -6,19 +6,18 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -121,635 +120,645 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams + fun toBuilder() = Builder().from(this) - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("member_permissions") - @ExcludeMissing - private val memberPermissions: JsonField> = JsonMissing.of(), - @JsonProperty("member_roles") - @ExcludeMissing - private val memberRoles: JsonField> = JsonMissing.of(), - @JsonProperty("org_name") - @ExcludeMissing - private val orgName: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + companion object { /** - * Name of the role + * Returns a mutable builder for constructing an instance of [RoleCreateParams]. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + * The following fields are required: + * ```java + * .name() + * ``` */ - fun name(): String = name.getRequired("name") + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoleCreateParams]. */ + class Builder internal constructor() { + + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(roleCreateParams: RoleCreateParams) = apply { + body = roleCreateParams.body.toBuilder() + additionalHeaders = roleCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = roleCreateParams.additionalQueryParams.toBuilder() + } + + /** Name of the role */ + fun name(name: String) = apply { body.name(name) } /** - * Textual description of the role + * Sets [Builder.name] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun name(name: JsonField) = apply { body.name(name) } + + /** Textual description of the role */ + fun description(description: String?) = apply { body.description(description) } + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) /** - * (permission, restrict_object_type) tuples which belong to this role + * Sets [Builder.description] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun memberPermissions(): Optional> = - Optional.ofNullable(memberPermissions.getNullable("member_permissions")) + fun description(description: JsonField) = apply { body.description(description) } + + /** (permission, restrict_object_type) tuples which belong to this role */ + fun memberPermissions(memberPermissions: List?) = apply { + body.memberPermissions(memberPermissions) + } + + /** Alias for calling [Builder.memberPermissions] with `memberPermissions.orElse(null)`. */ + fun memberPermissions(memberPermissions: Optional>) = + memberPermissions(memberPermissions.getOrNull()) /** - * Ids of the roles this role inherits from - * - * An inheriting role has all the permissions contained in its member roles, as well as all - * of their inherited permissions + * Sets [Builder.memberPermissions] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.memberPermissions] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. */ - fun memberRoles(): Optional> = - Optional.ofNullable(memberRoles.getNullable("member_roles")) + fun memberPermissions(memberPermissions: JsonField>) = apply { + body.memberPermissions(memberPermissions) + } /** - * For nearly all users, this parameter should be unnecessary. But in the rare case that - * your API key belongs to multiple organizations, you may specify the name of the - * organization the role belongs in. + * Adds a single [MemberPermission] to [memberPermissions]. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * @throws IllegalStateException if the field was previously set to a non-list. */ - fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) + fun addMemberPermission(memberPermission: MemberPermission) = apply { + body.addMemberPermission(memberPermission) + } /** - * Returns the raw JSON value of [name]. + * Ids of the roles this role inherits from * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + * An inheriting role has all the permissions contained in its member roles, as well as all + * of their inherited permissions */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + fun memberRoles(memberRoles: List?) = apply { body.memberRoles(memberRoles) } + + /** Alias for calling [Builder.memberRoles] with `memberRoles.orElse(null)`. */ + fun memberRoles(memberRoles: Optional>) = memberRoles(memberRoles.getOrNull()) /** - * Returns the raw JSON value of [description]. + * Sets [Builder.memberRoles] to an arbitrary JSON value. * - * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.memberRoles] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("description") - @ExcludeMissing - fun _description(): JsonField = description + fun memberRoles(memberRoles: JsonField>) = apply { + body.memberRoles(memberRoles) + } /** - * Returns the raw JSON value of [memberPermissions]. + * Adds a single [String] to [memberRoles]. * - * Unlike [memberPermissions], this method doesn't throw if the JSON field has an unexpected - * type. + * @throws IllegalStateException if the field was previously set to a non-list. */ - @JsonProperty("member_permissions") - @ExcludeMissing - fun _memberPermissions(): JsonField> = memberPermissions + fun addMemberRole(memberRole: String) = apply { body.addMemberRole(memberRole) } /** - * Returns the raw JSON value of [memberRoles]. - * - * Unlike [memberRoles], this method doesn't throw if the JSON field has an unexpected type. + * For nearly all users, this parameter should be unnecessary. But in the rare case that + * your API key belongs to multiple organizations, you may specify the name of the + * organization the role belongs in. */ - @JsonProperty("member_roles") - @ExcludeMissing - fun _memberRoles(): JsonField> = memberRoles + fun orgName(orgName: String?) = apply { body.orgName(orgName) } + + /** Alias for calling [Builder.orgName] with `orgName.orElse(null)`. */ + fun orgName(orgName: Optional) = orgName(orgName.getOrNull()) /** - * Returns the raw JSON value of [orgName]. + * Sets [Builder.orgName] to an arbitrary JSON value. * - * Unlike [orgName], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.orgName] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("org_name") @ExcludeMissing fun _orgName(): JsonField = orgName - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } + fun orgName(orgName: JsonField) = apply { body.orgName(orgName) } - name() - description() - memberPermissions().ifPresent { it.forEach { it.validate() } } - memberRoles() - orgName() - validated = true + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) } - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .name() - * ``` - */ - @JvmStatic fun builder() = Builder() + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) } - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var name: JsonField? = null - private var description: JsonField = JsonMissing.of() - private var memberPermissions: JsonField>? = null - private var memberRoles: JsonField>? = null - private var orgName: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - name = body.name - description = body.description - memberPermissions = body.memberPermissions.map { it.toMutableList() } - memberRoles = body.memberRoles.map { it.toMutableList() } - orgName = body.orgName - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** Name of the role */ - fun name(name: String) = name(JsonField.of(name)) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } - - /** Textual description of the role */ - fun description(description: String?) = description(JsonField.ofNullable(description)) - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) - - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun description(description: JsonField) = apply { - this.description = description + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) } - /** (permission, restrict_object_type) tuples which belong to this role */ - fun memberPermissions(memberPermissions: List?) = - memberPermissions(JsonField.ofNullable(memberPermissions)) + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - /** - * Alias for calling [Builder.memberPermissions] with `memberPermissions.orElse(null)`. - */ - fun memberPermissions(memberPermissions: Optional>) = - memberPermissions(memberPermissions.getOrNull()) + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } - /** - * Sets [Builder.memberPermissions] to an arbitrary JSON value. - * - * You should usually call [Builder.memberPermissions] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun memberPermissions(memberPermissions: JsonField>) = apply { - this.memberPermissions = memberPermissions.map { it.toMutableList() } - } + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** - * Adds a single [MemberPermission] to [memberPermissions]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addMemberPermission(memberPermission: MemberPermission) = apply { - memberPermissions = - (memberPermissions ?: JsonField.of(mutableListOf())).also { - checkKnown("memberPermissions", it).add(memberPermission) - } - } + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** - * Ids of the roles this role inherits from - * - * An inheriting role has all the permissions contained in its member roles, as well as - * all of their inherited permissions - */ - fun memberRoles(memberRoles: List?) = - memberRoles(JsonField.ofNullable(memberRoles)) + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } - /** Alias for calling [Builder.memberRoles] with `memberRoles.orElse(null)`. */ - fun memberRoles(memberRoles: Optional>) = - memberRoles(memberRoles.getOrNull()) + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - /** - * Sets [Builder.memberRoles] to an arbitrary JSON value. - * - * You should usually call [Builder.memberRoles] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun memberRoles(memberRoles: JsonField>) = apply { - this.memberRoles = memberRoles.map { it.toMutableList() } - } + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** - * Adds a single [String] to [memberRoles]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addMemberRole(memberRole: String) = apply { - memberRoles = - (memberRoles ?: JsonField.of(mutableListOf())).also { - checkKnown("memberRoles", it).add(memberRole) - } - } + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** - * For nearly all users, this parameter should be unnecessary. But in the rare case that - * your API key belongs to multiple organizations, you may specify the name of the - * organization the role belongs in. - */ - fun orgName(orgName: String?) = orgName(JsonField.ofNullable(orgName)) + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - /** Alias for calling [Builder.orgName] with `orgName.orElse(null)`. */ - fun orgName(orgName: Optional) = orgName(orgName.getOrNull()) + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** - * Sets [Builder.orgName] to an arbitrary JSON value. - * - * You should usually call [Builder.orgName] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun orgName(orgName: JsonField) = apply { this.orgName = orgName } + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("name", name), - description, - (memberPermissions ?: JsonMissing.of()).map { it.toImmutable() }, - (memberRoles ?: JsonMissing.of()).map { it.toImmutable() }, - orgName, - additionalProperties.toImmutable(), - ) + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + 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) } - return /* spotless:off */ other is Body && name == other.name && description == other.description && memberPermissions == other.memberPermissions && memberRoles == other.memberRoles && orgName == other.orgName && additionalProperties == other.additionalProperties /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, description, memberPermissions, memberRoles, orgName, additionalProperties) } - /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } - override fun hashCode(): Int = hashCode + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - override fun toString() = - "Body{name=$name, description=$description, memberPermissions=$memberPermissions, memberRoles=$memberRoles, orgName=$orgName, additionalProperties=$additionalProperties}" - } + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - fun toBuilder() = Builder().from(this) + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - companion object { + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } /** - * Returns a mutable builder for constructing an instance of [RoleCreateParams]. + * Returns an immutable instance of [RoleCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java * .name() * ``` + * + * @throws IllegalStateException if any required field is unset. */ - @JvmStatic fun builder() = Builder() + fun build(): RoleCreateParams = + RoleCreateParams(body.build(), additionalHeaders.build(), additionalQueryParams.build()) } - /** A builder for [RoleCreateParams]. */ - @NoAutoDetect - class Builder internal constructor() { - - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - - @JvmSynthetic - internal fun from(roleCreateParams: RoleCreateParams) = apply { - body = roleCreateParams.body.toBuilder() - additionalHeaders = roleCreateParams.additionalHeaders.toBuilder() - additionalQueryParams = roleCreateParams.additionalQueryParams.toBuilder() - } + @JvmSynthetic internal fun _body(): Body = body - /** Name of the role */ - fun name(name: String) = apply { body.name(name) } + override fun _headers(): Headers = additionalHeaders - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun name(name: JsonField) = apply { body.name(name) } + override fun _queryParams(): QueryParams = additionalQueryParams - /** Textual description of the role */ - fun description(description: String?) = apply { body.description(description) } + class Body + private constructor( + private val name: JsonField, + private val description: JsonField, + private val memberPermissions: JsonField>, + private val memberRoles: JsonField>, + private val orgName: JsonField, + private val additionalProperties: MutableMap, + ) { - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("member_permissions") + @ExcludeMissing + memberPermissions: JsonField> = JsonMissing.of(), + @JsonProperty("member_roles") + @ExcludeMissing + memberRoles: JsonField> = JsonMissing.of(), + @JsonProperty("org_name") @ExcludeMissing orgName: JsonField = JsonMissing.of(), + ) : this(name, description, memberPermissions, memberRoles, orgName, mutableMapOf()) /** - * Sets [Builder.description] to an arbitrary JSON value. + * Name of the role * - * You should usually call [Builder.description] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun description(description: JsonField) = apply { body.description(description) } - - /** (permission, restrict_object_type) tuples which belong to this role */ - fun memberPermissions(memberPermissions: List?) = apply { - body.memberPermissions(memberPermissions) - } - - /** Alias for calling [Builder.memberPermissions] with `memberPermissions.orElse(null)`. */ - fun memberPermissions(memberPermissions: Optional>) = - memberPermissions(memberPermissions.getOrNull()) + fun name(): String = name.getRequired("name") /** - * Sets [Builder.memberPermissions] to an arbitrary JSON value. + * Textual description of the role * - * You should usually call [Builder.memberPermissions] with a well-typed - * `List` value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun memberPermissions(memberPermissions: JsonField>) = apply { - body.memberPermissions(memberPermissions) - } + fun description(): Optional = + Optional.ofNullable(description.getNullable("description")) /** - * Adds a single [MemberPermission] to [memberPermissions]. + * (permission, restrict_object_type) tuples which belong to this role * - * @throws IllegalStateException if the field was previously set to a non-list. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun addMemberPermission(memberPermission: MemberPermission) = apply { - body.addMemberPermission(memberPermission) - } + fun memberPermissions(): Optional> = + Optional.ofNullable(memberPermissions.getNullable("member_permissions")) /** * Ids of the roles this role inherits from * * An inheriting role has all the permissions contained in its member roles, as well as all * of their inherited permissions + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun memberRoles(memberRoles: List?) = apply { body.memberRoles(memberRoles) } + fun memberRoles(): Optional> = + Optional.ofNullable(memberRoles.getNullable("member_roles")) - /** Alias for calling [Builder.memberRoles] with `memberRoles.orElse(null)`. */ - fun memberRoles(memberRoles: Optional>) = memberRoles(memberRoles.getOrNull()) + /** + * For nearly all users, this parameter should be unnecessary. But in the rare case that + * your API key belongs to multiple organizations, you may specify the name of the + * organization the role belongs in. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) /** - * Sets [Builder.memberRoles] to an arbitrary JSON value. + * Returns the raw JSON value of [name]. * - * You should usually call [Builder.memberRoles] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. */ - fun memberRoles(memberRoles: JsonField>) = apply { - body.memberRoles(memberRoles) - } + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name /** - * Adds a single [String] to [memberRoles]. + * Returns the raw JSON value of [description]. * - * @throws IllegalStateException if the field was previously set to a non-list. + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. */ - fun addMemberRole(memberRole: String) = apply { body.addMemberRole(memberRole) } + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description /** - * For nearly all users, this parameter should be unnecessary. But in the rare case that - * your API key belongs to multiple organizations, you may specify the name of the - * organization the role belongs in. + * Returns the raw JSON value of [memberPermissions]. + * + * Unlike [memberPermissions], this method doesn't throw if the JSON field has an unexpected + * type. */ - fun orgName(orgName: String?) = apply { body.orgName(orgName) } + @JsonProperty("member_permissions") + @ExcludeMissing + fun _memberPermissions(): JsonField> = memberPermissions - /** Alias for calling [Builder.orgName] with `orgName.orElse(null)`. */ - fun orgName(orgName: Optional) = orgName(orgName.getOrNull()) + /** + * Returns the raw JSON value of [memberRoles]. + * + * Unlike [memberRoles], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("member_roles") + @ExcludeMissing + fun _memberRoles(): JsonField> = memberRoles /** - * Sets [Builder.orgName] to an arbitrary JSON value. + * Returns the raw JSON value of [orgName]. * - * You should usually call [Builder.orgName] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [orgName], this method doesn't throw if the JSON field has an unexpected type. */ - fun orgName(orgName: JsonField) = apply { body.orgName(orgName) } + @JsonProperty("org_name") @ExcludeMissing fun _orgName(): JsonField = orgName - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() } - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var name: JsonField? = null + private var description: JsonField = JsonMissing.of() + private var memberPermissions: JsonField>? = null + private var memberRoles: JsonField>? = null + private var orgName: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + name = body.name + description = body.description + memberPermissions = body.memberPermissions.map { it.toMutableList() } + memberRoles = body.memberRoles.map { it.toMutableList() } + orgName = body.orgName + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** Name of the role */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** Textual description of the role */ + fun description(description: String?) = description(JsonField.ofNullable(description)) + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun description(description: JsonField) = apply { + this.description = description } - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } + /** (permission, restrict_object_type) tuples which belong to this role */ + fun memberPermissions(memberPermissions: List?) = + memberPermissions(JsonField.ofNullable(memberPermissions)) - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * Alias for calling [Builder.memberPermissions] with `memberPermissions.orElse(null)`. + */ + fun memberPermissions(memberPermissions: Optional>) = + memberPermissions(memberPermissions.getOrNull()) - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * Sets [Builder.memberPermissions] to an arbitrary JSON value. + * + * You should usually call [Builder.memberPermissions] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun memberPermissions(memberPermissions: JsonField>) = apply { + this.memberPermissions = memberPermissions.map { it.toMutableList() } + } - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } + /** + * Adds a single [MemberPermission] to [memberPermissions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addMemberPermission(memberPermission: MemberPermission) = apply { + memberPermissions = + (memberPermissions ?: JsonField.of(mutableListOf())).also { + checkKnown("memberPermissions", it).add(memberPermission) + } + } - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } + /** + * Ids of the roles this role inherits from + * + * An inheriting role has all the permissions contained in its member roles, as well as + * all of their inherited permissions + */ + fun memberRoles(memberRoles: List?) = + memberRoles(JsonField.ofNullable(memberRoles)) - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** Alias for calling [Builder.memberRoles] with `memberRoles.orElse(null)`. */ + fun memberRoles(memberRoles: Optional>) = + memberRoles(memberRoles.getOrNull()) - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** + * Sets [Builder.memberRoles] to an arbitrary JSON value. + * + * You should usually call [Builder.memberRoles] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun memberRoles(memberRoles: JsonField>) = apply { + this.memberRoles = memberRoles.map { it.toMutableList() } + } - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } + /** + * Adds a single [String] to [memberRoles]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addMemberRole(memberRole: String) = apply { + memberRoles = + (memberRoles ?: JsonField.of(mutableListOf())).also { + checkKnown("memberRoles", it).add(memberRole) + } + } - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } + /** + * For nearly all users, this parameter should be unnecessary. But in the rare case that + * your API key belongs to multiple organizations, you may specify the name of the + * organization the role belongs in. + */ + fun orgName(orgName: String?) = orgName(JsonField.ofNullable(orgName)) - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** Alias for calling [Builder.orgName] with `orgName.orElse(null)`. */ + fun orgName(orgName: Optional) = orgName(orgName.getOrNull()) - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** + * Sets [Builder.orgName] to an arbitrary JSON value. + * + * You should usually call [Builder.orgName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun orgName(orgName: JsonField) = apply { this.orgName = orgName } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("name", name), + description, + (memberPermissions ?: JsonMissing.of()).map { it.toImmutable() }, + (memberRoles ?: JsonMissing.of()).map { it.toImmutable() }, + orgName, + additionalProperties.toMutableMap(), + ) } - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } + private var validated: Boolean = false - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + fun validate(): Body = apply { + if (validated) { + return@apply } - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) + name() + description() + memberPermissions().ifPresent { it.forEach { it.validate() } } + memberRoles() + orgName() + validated = true } - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + return /* spotless:off */ other is Body && name == other.name && description == other.description && memberPermissions == other.memberPermissions && memberRoles == other.memberRoles && orgName == other.orgName && additionalProperties == other.additionalProperties /* spotless:on */ } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) - } - - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(name, description, memberPermissions, memberRoles, orgName, additionalProperties) } + /* spotless:on */ - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) - } + override fun hashCode(): Int = hashCode - /** - * Returns an immutable instance of [RoleCreateParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): RoleCreateParams = - RoleCreateParams(body.build(), additionalHeaders.build(), additionalQueryParams.build()) + override fun toString() = + "Body{name=$name, description=$description, memberPermissions=$memberPermissions, memberRoles=$memberRoles, orgName=$orgName, additionalProperties=$additionalProperties}" } - @NoAutoDetect class MemberPermission - @JsonCreator private constructor( - @JsonProperty("permission") - @ExcludeMissing - private val permission: JsonField = JsonMissing.of(), - @JsonProperty("restrict_object_type") - @ExcludeMissing - private val restrictObjectType: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val permission: JsonField, + private val restrictObjectType: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("permission") + @ExcludeMissing + permission: JsonField = JsonMissing.of(), + @JsonProperty("restrict_object_type") + @ExcludeMissing + restrictObjectType: JsonField = JsonMissing.of(), + ) : this(permission, restrictObjectType, mutableMapOf()) + /** * Each permission permits a certain type of operation on an object in the system * @@ -788,21 +797,15 @@ private constructor( @ExcludeMissing fun _restrictObjectType(): JsonField = restrictObjectType + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): MemberPermission = apply { - if (validated) { - return@apply - } - - permission() - restrictObjectType() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -909,10 +912,22 @@ private constructor( MemberPermission( checkRequired("permission", permission), restrictObjectType, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): MemberPermission = apply { + if (validated) { + return@apply + } + + permission() + restrictObjectType() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleDeleteParams.kt index c5b59886..4c6028d6 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleDeleteParams.kt @@ -2,13 +2,15 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.toImmutable +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import java.util.Collections import java.util.Objects import java.util.Optional @@ -18,7 +20,7 @@ private constructor( private val roleId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: Map, + private val additionalBodyProperties: MutableMap, ) : Params { /** Role id */ @@ -28,21 +30,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _additionalBodyProperties(): Map = additionalBodyProperties - - @JvmSynthetic - internal fun _body(): Optional> = - Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - - fun _pathParam(index: Int): String = - when (index) { - 0 -> roleId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders + @JsonAnySetter + private fun putAdditionalBodyProperty(key: String, value: JsonValue) { + additionalBodyProperties.put(key, value) + } - override fun _queryParams(): QueryParams = additionalQueryParams + @JsonAnyGetter + @ExcludeMissing + fun _additionalBodyProperties(): Map = + Collections.unmodifiableMap(additionalBodyProperties) fun toBuilder() = Builder().from(this) @@ -60,7 +56,6 @@ private constructor( } /** A builder for [RoleDeleteParams]. */ - @NoAutoDetect class Builder internal constructor() { private var roleId: String? = null @@ -216,10 +211,24 @@ private constructor( checkRequired("roleId", roleId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toImmutable(), + additionalBodyProperties.toMutableMap(), ) } + @JvmSynthetic + internal fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> roleId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt index 9cae9580..084bdcb4 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.blocking.RoleService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -81,23 +79,30 @@ private constructor( RoleListPage(rolesService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -155,7 +160,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt index 8e13282e..76e6b11d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.async.RoleServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -83,23 +81,30 @@ private constructor( RoleListPageAsync(rolesService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -157,7 +162,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListParams.kt index 333d1d99..a75c101a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListParams.kt @@ -5,7 +5,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.BaseDeserializer import com.braintrustdata.api.core.BaseSerializer import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers @@ -75,31 +74,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = - QueryParams.builder() - .apply { - endingBefore?.let { put("ending_before", it) } - ids?.accept( - object : Ids.Visitor { - override fun visitString(string: String) { - put("ids", string) - } - - override fun visitStrings(strings: List) { - put("ids", strings.joinToString(",")) - } - } - ) - limit?.let { put("limit", it.toString()) } - orgName?.let { put("org_name", it) } - roleName?.let { put("role_name", it) } - startingAfter?.let { put("starting_after", it) } - putAll(additionalQueryParams) - } - .build() - fun toBuilder() = Builder().from(this) companion object { @@ -111,7 +85,6 @@ private constructor( } /** A builder for [RoleListParams]. */ - @NoAutoDetect class Builder internal constructor() { private var endingBefore: String? = null @@ -316,6 +289,31 @@ private constructor( ) } + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + endingBefore?.let { put("ending_before", it) } + ids?.accept( + object : Ids.Visitor { + override fun visitString(string: String) { + put("ids", string) + } + + override fun visitStrings(strings: List) { + put("ids", strings.joinToString(",")) + } + } + ) + limit?.let { put("limit", it.toString()) } + orgName?.let { put("org_name", it) } + roleName?.let { put("role_name", it) } + startingAfter?.let { put("starting_after", it) } + putAll(additionalQueryParams) + } + .build() + /** * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleReplaceParams.kt index 97635d9d..73ece3a4 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleReplaceParams.kt @@ -6,19 +6,18 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -121,639 +120,649 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams + fun toBuilder() = Builder().from(this) - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("member_permissions") - @ExcludeMissing - private val memberPermissions: JsonField> = JsonMissing.of(), - @JsonProperty("member_roles") - @ExcludeMissing - private val memberRoles: JsonField> = JsonMissing.of(), - @JsonProperty("org_name") - @ExcludeMissing - private val orgName: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + companion object { /** - * Name of the role + * Returns a mutable builder for constructing an instance of [RoleReplaceParams]. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + * The following fields are required: + * ```java + * .name() + * ``` */ - fun name(): String = name.getRequired("name") + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoleReplaceParams]. */ + class Builder internal constructor() { + + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(roleReplaceParams: RoleReplaceParams) = apply { + body = roleReplaceParams.body.toBuilder() + additionalHeaders = roleReplaceParams.additionalHeaders.toBuilder() + additionalQueryParams = roleReplaceParams.additionalQueryParams.toBuilder() + } + + /** Name of the role */ + fun name(name: String) = apply { body.name(name) } /** - * Textual description of the role + * Sets [Builder.name] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun name(name: JsonField) = apply { body.name(name) } + + /** Textual description of the role */ + fun description(description: String?) = apply { body.description(description) } + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) /** - * (permission, restrict_object_type) tuples which belong to this role + * Sets [Builder.description] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun memberPermissions(): Optional> = - Optional.ofNullable(memberPermissions.getNullable("member_permissions")) + fun description(description: JsonField) = apply { body.description(description) } + + /** (permission, restrict_object_type) tuples which belong to this role */ + fun memberPermissions(memberPermissions: List?) = apply { + body.memberPermissions(memberPermissions) + } + + /** Alias for calling [Builder.memberPermissions] with `memberPermissions.orElse(null)`. */ + fun memberPermissions(memberPermissions: Optional>) = + memberPermissions(memberPermissions.getOrNull()) /** - * Ids of the roles this role inherits from - * - * An inheriting role has all the permissions contained in its member roles, as well as all - * of their inherited permissions + * Sets [Builder.memberPermissions] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.memberPermissions] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. */ - fun memberRoles(): Optional> = - Optional.ofNullable(memberRoles.getNullable("member_roles")) + fun memberPermissions(memberPermissions: JsonField>) = apply { + body.memberPermissions(memberPermissions) + } /** - * For nearly all users, this parameter should be unnecessary. But in the rare case that - * your API key belongs to multiple organizations, you may specify the name of the - * organization the role belongs in. + * Adds a single [MemberPermission] to [memberPermissions]. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * @throws IllegalStateException if the field was previously set to a non-list. */ - fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) + fun addMemberPermission(memberPermission: MemberPermission) = apply { + body.addMemberPermission(memberPermission) + } /** - * Returns the raw JSON value of [name]. + * Ids of the roles this role inherits from * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + * An inheriting role has all the permissions contained in its member roles, as well as all + * of their inherited permissions */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + fun memberRoles(memberRoles: List?) = apply { body.memberRoles(memberRoles) } + + /** Alias for calling [Builder.memberRoles] with `memberRoles.orElse(null)`. */ + fun memberRoles(memberRoles: Optional>) = memberRoles(memberRoles.getOrNull()) /** - * Returns the raw JSON value of [description]. + * Sets [Builder.memberRoles] to an arbitrary JSON value. * - * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.memberRoles] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("description") - @ExcludeMissing - fun _description(): JsonField = description + fun memberRoles(memberRoles: JsonField>) = apply { + body.memberRoles(memberRoles) + } /** - * Returns the raw JSON value of [memberPermissions]. + * Adds a single [String] to [memberRoles]. * - * Unlike [memberPermissions], this method doesn't throw if the JSON field has an unexpected - * type. + * @throws IllegalStateException if the field was previously set to a non-list. */ - @JsonProperty("member_permissions") - @ExcludeMissing - fun _memberPermissions(): JsonField> = memberPermissions + fun addMemberRole(memberRole: String) = apply { body.addMemberRole(memberRole) } /** - * Returns the raw JSON value of [memberRoles]. - * - * Unlike [memberRoles], this method doesn't throw if the JSON field has an unexpected type. + * For nearly all users, this parameter should be unnecessary. But in the rare case that + * your API key belongs to multiple organizations, you may specify the name of the + * organization the role belongs in. */ - @JsonProperty("member_roles") - @ExcludeMissing - fun _memberRoles(): JsonField> = memberRoles + fun orgName(orgName: String?) = apply { body.orgName(orgName) } + + /** Alias for calling [Builder.orgName] with `orgName.orElse(null)`. */ + fun orgName(orgName: Optional) = orgName(orgName.getOrNull()) /** - * Returns the raw JSON value of [orgName]. + * Sets [Builder.orgName] to an arbitrary JSON value. * - * Unlike [orgName], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.orgName] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("org_name") @ExcludeMissing fun _orgName(): JsonField = orgName - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } + fun orgName(orgName: JsonField) = apply { body.orgName(orgName) } - name() - description() - memberPermissions().ifPresent { it.forEach { it.validate() } } - memberRoles() - orgName() - validated = true + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) } - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .name() - * ``` - */ - @JvmStatic fun builder() = Builder() + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) } - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var name: JsonField? = null - private var description: JsonField = JsonMissing.of() - private var memberPermissions: JsonField>? = null - private var memberRoles: JsonField>? = null - private var orgName: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - name = body.name - description = body.description - memberPermissions = body.memberPermissions.map { it.toMutableList() } - memberRoles = body.memberRoles.map { it.toMutableList() } - orgName = body.orgName - additionalProperties = body.additionalProperties.toMutableMap() + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) } - /** Name of the role */ - fun name(name: String) = name(JsonField.of(name)) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } - - /** Textual description of the role */ - fun description(description: String?) = description(JsonField.ofNullable(description)) - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) - - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun description(description: JsonField) = apply { - this.description = description - } + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - /** (permission, restrict_object_type) tuples which belong to this role */ - fun memberPermissions(memberPermissions: List?) = - memberPermissions(JsonField.ofNullable(memberPermissions)) + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } - /** - * Alias for calling [Builder.memberPermissions] with `memberPermissions.orElse(null)`. - */ - fun memberPermissions(memberPermissions: Optional>) = - memberPermissions(memberPermissions.getOrNull()) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** - * Sets [Builder.memberPermissions] to an arbitrary JSON value. - * - * You should usually call [Builder.memberPermissions] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun memberPermissions(memberPermissions: JsonField>) = apply { - this.memberPermissions = memberPermissions.map { it.toMutableList() } - } + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** - * Adds a single [MemberPermission] to [memberPermissions]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addMemberPermission(memberPermission: MemberPermission) = apply { - memberPermissions = - (memberPermissions ?: JsonField.of(mutableListOf())).also { - checkKnown("memberPermissions", it).add(memberPermission) - } - } + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } - /** - * Ids of the roles this role inherits from - * - * An inheriting role has all the permissions contained in its member roles, as well as - * all of their inherited permissions - */ - fun memberRoles(memberRoles: List?) = - memberRoles(JsonField.ofNullable(memberRoles)) + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - /** Alias for calling [Builder.memberRoles] with `memberRoles.orElse(null)`. */ - fun memberRoles(memberRoles: Optional>) = - memberRoles(memberRoles.getOrNull()) + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** - * Sets [Builder.memberRoles] to an arbitrary JSON value. - * - * You should usually call [Builder.memberRoles] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun memberRoles(memberRoles: JsonField>) = apply { - this.memberRoles = memberRoles.map { it.toMutableList() } - } + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** - * Adds a single [String] to [memberRoles]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addMemberRole(memberRole: String) = apply { - memberRoles = - (memberRoles ?: JsonField.of(mutableListOf())).also { - checkKnown("memberRoles", it).add(memberRole) - } - } + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - /** - * For nearly all users, this parameter should be unnecessary. But in the rare case that - * your API key belongs to multiple organizations, you may specify the name of the - * organization the role belongs in. - */ - fun orgName(orgName: String?) = orgName(JsonField.ofNullable(orgName)) + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** Alias for calling [Builder.orgName] with `orgName.orElse(null)`. */ - fun orgName(orgName: Optional) = orgName(orgName.getOrNull()) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Sets [Builder.orgName] to an arbitrary JSON value. - * - * You should usually call [Builder.orgName] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun orgName(orgName: JsonField) = apply { this.orgName = orgName } + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("name", name), - description, - (memberPermissions ?: JsonMissing.of()).map { it.toImmutable() }, - (memberRoles ?: JsonMissing.of()).map { it.toImmutable() }, - orgName, - additionalProperties.toImmutable(), - ) + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - return /* spotless:off */ other is Body && name == other.name && description == other.description && memberPermissions == other.memberPermissions && memberRoles == other.memberRoles && orgName == other.orgName && additionalProperties == other.additionalProperties /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, description, memberPermissions, memberRoles, orgName, additionalProperties) } - /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } - override fun hashCode(): Int = hashCode + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - override fun toString() = - "Body{name=$name, description=$description, memberPermissions=$memberPermissions, memberRoles=$memberRoles, orgName=$orgName, additionalProperties=$additionalProperties}" - } + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - fun toBuilder() = Builder().from(this) + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - companion object { + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } /** - * Returns a mutable builder for constructing an instance of [RoleReplaceParams]. + * Returns an immutable instance of [RoleReplaceParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java * .name() * ``` + * + * @throws IllegalStateException if any required field is unset. */ - @JvmStatic fun builder() = Builder() + fun build(): RoleReplaceParams = + RoleReplaceParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) } - /** A builder for [RoleReplaceParams]. */ - @NoAutoDetect - class Builder internal constructor() { - - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - - @JvmSynthetic - internal fun from(roleReplaceParams: RoleReplaceParams) = apply { - body = roleReplaceParams.body.toBuilder() - additionalHeaders = roleReplaceParams.additionalHeaders.toBuilder() - additionalQueryParams = roleReplaceParams.additionalQueryParams.toBuilder() - } + @JvmSynthetic internal fun _body(): Body = body - /** Name of the role */ - fun name(name: String) = apply { body.name(name) } + override fun _headers(): Headers = additionalHeaders - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun name(name: JsonField) = apply { body.name(name) } + override fun _queryParams(): QueryParams = additionalQueryParams - /** Textual description of the role */ - fun description(description: String?) = apply { body.description(description) } + class Body + private constructor( + private val name: JsonField, + private val description: JsonField, + private val memberPermissions: JsonField>, + private val memberRoles: JsonField>, + private val orgName: JsonField, + private val additionalProperties: MutableMap, + ) { - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("member_permissions") + @ExcludeMissing + memberPermissions: JsonField> = JsonMissing.of(), + @JsonProperty("member_roles") + @ExcludeMissing + memberRoles: JsonField> = JsonMissing.of(), + @JsonProperty("org_name") @ExcludeMissing orgName: JsonField = JsonMissing.of(), + ) : this(name, description, memberPermissions, memberRoles, orgName, mutableMapOf()) /** - * Sets [Builder.description] to an arbitrary JSON value. + * Name of the role * - * You should usually call [Builder.description] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun description(description: JsonField) = apply { body.description(description) } - - /** (permission, restrict_object_type) tuples which belong to this role */ - fun memberPermissions(memberPermissions: List?) = apply { - body.memberPermissions(memberPermissions) - } - - /** Alias for calling [Builder.memberPermissions] with `memberPermissions.orElse(null)`. */ - fun memberPermissions(memberPermissions: Optional>) = - memberPermissions(memberPermissions.getOrNull()) + fun name(): String = name.getRequired("name") /** - * Sets [Builder.memberPermissions] to an arbitrary JSON value. + * Textual description of the role * - * You should usually call [Builder.memberPermissions] with a well-typed - * `List` value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun memberPermissions(memberPermissions: JsonField>) = apply { - body.memberPermissions(memberPermissions) - } + fun description(): Optional = + Optional.ofNullable(description.getNullable("description")) /** - * Adds a single [MemberPermission] to [memberPermissions]. + * (permission, restrict_object_type) tuples which belong to this role * - * @throws IllegalStateException if the field was previously set to a non-list. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun addMemberPermission(memberPermission: MemberPermission) = apply { - body.addMemberPermission(memberPermission) - } + fun memberPermissions(): Optional> = + Optional.ofNullable(memberPermissions.getNullable("member_permissions")) /** * Ids of the roles this role inherits from * * An inheriting role has all the permissions contained in its member roles, as well as all * of their inherited permissions + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun memberRoles(memberRoles: List?) = apply { body.memberRoles(memberRoles) } + fun memberRoles(): Optional> = + Optional.ofNullable(memberRoles.getNullable("member_roles")) - /** Alias for calling [Builder.memberRoles] with `memberRoles.orElse(null)`. */ - fun memberRoles(memberRoles: Optional>) = memberRoles(memberRoles.getOrNull()) + /** + * For nearly all users, this parameter should be unnecessary. But in the rare case that + * your API key belongs to multiple organizations, you may specify the name of the + * organization the role belongs in. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) /** - * Sets [Builder.memberRoles] to an arbitrary JSON value. + * Returns the raw JSON value of [name]. * - * You should usually call [Builder.memberRoles] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. */ - fun memberRoles(memberRoles: JsonField>) = apply { - body.memberRoles(memberRoles) - } + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name /** - * Adds a single [String] to [memberRoles]. + * Returns the raw JSON value of [description]. * - * @throws IllegalStateException if the field was previously set to a non-list. + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. */ - fun addMemberRole(memberRole: String) = apply { body.addMemberRole(memberRole) } + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description /** - * For nearly all users, this parameter should be unnecessary. But in the rare case that - * your API key belongs to multiple organizations, you may specify the name of the - * organization the role belongs in. + * Returns the raw JSON value of [memberPermissions]. + * + * Unlike [memberPermissions], this method doesn't throw if the JSON field has an unexpected + * type. */ - fun orgName(orgName: String?) = apply { body.orgName(orgName) } + @JsonProperty("member_permissions") + @ExcludeMissing + fun _memberPermissions(): JsonField> = memberPermissions - /** Alias for calling [Builder.orgName] with `orgName.orElse(null)`. */ - fun orgName(orgName: Optional) = orgName(orgName.getOrNull()) + /** + * Returns the raw JSON value of [memberRoles]. + * + * Unlike [memberRoles], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("member_roles") + @ExcludeMissing + fun _memberRoles(): JsonField> = memberRoles /** - * Sets [Builder.orgName] to an arbitrary JSON value. + * Returns the raw JSON value of [orgName]. * - * You should usually call [Builder.orgName] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [orgName], this method doesn't throw if the JSON field has an unexpected type. */ - fun orgName(orgName: JsonField) = apply { body.orgName(orgName) } + @JsonProperty("org_name") @ExcludeMissing fun _orgName(): JsonField = orgName - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() } - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var name: JsonField? = null + private var description: JsonField = JsonMissing.of() + private var memberPermissions: JsonField>? = null + private var memberRoles: JsonField>? = null + private var orgName: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + name = body.name + description = body.description + memberPermissions = body.memberPermissions.map { it.toMutableList() } + memberRoles = body.memberRoles.map { it.toMutableList() } + orgName = body.orgName + additionalProperties = body.additionalProperties.toMutableMap() } - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + /** Name of the role */ + fun name(name: String) = name(JsonField.of(name)) - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** Textual description of the role */ + fun description(description: String?) = description(JsonField.ofNullable(description)) + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** (permission, restrict_object_type) tuples which belong to this role */ + fun memberPermissions(memberPermissions: List?) = + memberPermissions(JsonField.ofNullable(memberPermissions)) - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * Alias for calling [Builder.memberPermissions] with `memberPermissions.orElse(null)`. + */ + fun memberPermissions(memberPermissions: Optional>) = + memberPermissions(memberPermissions.getOrNull()) - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } + /** + * Sets [Builder.memberPermissions] to an arbitrary JSON value. + * + * You should usually call [Builder.memberPermissions] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun memberPermissions(memberPermissions: JsonField>) = apply { + this.memberPermissions = memberPermissions.map { it.toMutableList() } + } - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } + /** + * Adds a single [MemberPermission] to [memberPermissions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addMemberPermission(memberPermission: MemberPermission) = apply { + memberPermissions = + (memberPermissions ?: JsonField.of(mutableListOf())).also { + checkKnown("memberPermissions", it).add(memberPermission) + } + } - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** + * Ids of the roles this role inherits from + * + * An inheriting role has all the permissions contained in its member roles, as well as + * all of their inherited permissions + */ + fun memberRoles(memberRoles: List?) = + memberRoles(JsonField.ofNullable(memberRoles)) - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** Alias for calling [Builder.memberRoles] with `memberRoles.orElse(null)`. */ + fun memberRoles(memberRoles: Optional>) = + memberRoles(memberRoles.getOrNull()) - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } + /** + * Sets [Builder.memberRoles] to an arbitrary JSON value. + * + * You should usually call [Builder.memberRoles] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun memberRoles(memberRoles: JsonField>) = apply { + this.memberRoles = memberRoles.map { it.toMutableList() } + } - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } + /** + * Adds a single [String] to [memberRoles]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addMemberRole(memberRole: String) = apply { + memberRoles = + (memberRoles ?: JsonField.of(mutableListOf())).also { + checkKnown("memberRoles", it).add(memberRole) + } + } - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** + * For nearly all users, this parameter should be unnecessary. But in the rare case that + * your API key belongs to multiple organizations, you may specify the name of the + * organization the role belongs in. + */ + fun orgName(orgName: String?) = orgName(JsonField.ofNullable(orgName)) - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** Alias for calling [Builder.orgName] with `orgName.orElse(null)`. */ + fun orgName(orgName: Optional) = orgName(orgName.getOrNull()) - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + /** + * Sets [Builder.orgName] to an arbitrary JSON value. + * + * You should usually call [Builder.orgName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun orgName(orgName: JsonField) = apply { this.orgName = orgName } - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("name", name), + description, + (memberPermissions ?: JsonMissing.of()).map { it.toImmutable() }, + (memberRoles ?: JsonMissing.of()).map { it.toImmutable() }, + orgName, + additionalProperties.toMutableMap(), + ) } - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply } - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) + name() + description() + memberPermissions().ifPresent { it.forEach { it.validate() } } + memberRoles() + orgName() + validated = true } - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + return /* spotless:off */ other is Body && name == other.name && description == other.description && memberPermissions == other.memberPermissions && memberRoles == other.memberRoles && orgName == other.orgName && additionalProperties == other.additionalProperties /* spotless:on */ } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) - } - - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(name, description, memberPermissions, memberRoles, orgName, additionalProperties) } + /* spotless:on */ - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) - } + override fun hashCode(): Int = hashCode - /** - * Returns an immutable instance of [RoleReplaceParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): RoleReplaceParams = - RoleReplaceParams( - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + override fun toString() = + "Body{name=$name, description=$description, memberPermissions=$memberPermissions, memberRoles=$memberRoles, orgName=$orgName, additionalProperties=$additionalProperties}" } - @NoAutoDetect class MemberPermission - @JsonCreator private constructor( - @JsonProperty("permission") - @ExcludeMissing - private val permission: JsonField = JsonMissing.of(), - @JsonProperty("restrict_object_type") - @ExcludeMissing - private val restrictObjectType: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val permission: JsonField, + private val restrictObjectType: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("permission") + @ExcludeMissing + permission: JsonField = JsonMissing.of(), + @JsonProperty("restrict_object_type") + @ExcludeMissing + restrictObjectType: JsonField = JsonMissing.of(), + ) : this(permission, restrictObjectType, mutableMapOf()) + /** * Each permission permits a certain type of operation on an object in the system * @@ -792,21 +801,15 @@ private constructor( @ExcludeMissing fun _restrictObjectType(): JsonField = restrictObjectType + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): MemberPermission = apply { - if (validated) { - return@apply - } - - permission() - restrictObjectType() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -913,10 +916,22 @@ private constructor( MemberPermission( checkRequired("permission", permission), restrictObjectType, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): MemberPermission = apply { + if (validated) { + return@apply + } + + permission() + restrictObjectType() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleRetrieveParams.kt index e825713b..2b82d6ea 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleRetrieveParams.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers @@ -24,16 +23,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _pathParam(index: Int): String = - when (index) { - 0 -> roleId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - fun toBuilder() = Builder().from(this) companion object { @@ -50,7 +39,6 @@ private constructor( } /** A builder for [RoleRetrieveParams]. */ - @NoAutoDetect class Builder internal constructor() { private var roleId: String? = null @@ -185,6 +173,16 @@ private constructor( ) } + fun _pathParam(index: Int): String = + when (index) { + 0 -> roleId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleUpdateParams.kt index fee941e4..c45164b0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleUpdateParams.kt @@ -6,19 +6,18 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -140,767 +139,787 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body + fun toBuilder() = Builder().from(this) - fun _pathParam(index: Int): String = - when (index) { - 0 -> roleId - else -> "" - } + companion object { - override fun _headers(): Headers = additionalHeaders + /** + * Returns a mutable builder for constructing an instance of [RoleUpdateParams]. + * + * The following fields are required: + * ```java + * .roleId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun _queryParams(): QueryParams = additionalQueryParams + /** A builder for [RoleUpdateParams]. */ + class Builder internal constructor() { - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("add_member_permissions") - @ExcludeMissing - private val addMemberPermissions: JsonField> = JsonMissing.of(), - @JsonProperty("add_member_roles") - @ExcludeMissing - private val addMemberRoles: JsonField> = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("remove_member_permissions") - @ExcludeMissing - private val removeMemberPermissions: JsonField> = - JsonMissing.of(), - @JsonProperty("remove_member_roles") - @ExcludeMissing - private val removeMemberRoles: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + private var roleId: String? = null + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(roleUpdateParams: RoleUpdateParams) = apply { + roleId = roleUpdateParams.roleId + body = roleUpdateParams.body.toBuilder() + additionalHeaders = roleUpdateParams.additionalHeaders.toBuilder() + additionalQueryParams = roleUpdateParams.additionalQueryParams.toBuilder() + } + + /** Role id */ + fun roleId(roleId: String) = apply { this.roleId = roleId } + + /** A list of permissions to add to the role */ + fun addMemberPermissions(addMemberPermissions: List?) = apply { + body.addMemberPermissions(addMemberPermissions) + } /** - * A list of permissions to add to the role - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * Alias for calling [Builder.addMemberPermissions] with + * `addMemberPermissions.orElse(null)`. */ - fun addMemberPermissions(): Optional> = - Optional.ofNullable(addMemberPermissions.getNullable("add_member_permissions")) + fun addMemberPermissions(addMemberPermissions: Optional>) = + addMemberPermissions(addMemberPermissions.getOrNull()) /** - * A list of role IDs to add to the role's inheriting-from set + * Sets [Builder.addMemberPermissions] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.addMemberPermissions] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. */ - fun addMemberRoles(): Optional> = - Optional.ofNullable(addMemberRoles.getNullable("add_member_roles")) + fun addMemberPermissions(addMemberPermissions: JsonField>) = + apply { + body.addMemberPermissions(addMemberPermissions) + } /** - * Textual description of the role + * Adds a single [AddMemberPermission] to [addMemberPermissions]. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * @throws IllegalStateException if the field was previously set to a non-list. */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun addAddMemberPermission(addMemberPermission: AddMemberPermission) = apply { + body.addAddMemberPermission(addMemberPermission) + } + + /** A list of role IDs to add to the role's inheriting-from set */ + fun addMemberRoles(addMemberRoles: List?) = apply { + body.addMemberRoles(addMemberRoles) + } + + /** Alias for calling [Builder.addMemberRoles] with `addMemberRoles.orElse(null)`. */ + fun addMemberRoles(addMemberRoles: Optional>) = + addMemberRoles(addMemberRoles.getOrNull()) /** - * Name of the role + * Sets [Builder.addMemberRoles] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.addMemberRoles] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun addMemberRoles(addMemberRoles: JsonField>) = apply { + body.addMemberRoles(addMemberRoles) + } /** - * A list of permissions to remove from the role + * Adds a single [String] to [addMemberRoles]. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * @throws IllegalStateException if the field was previously set to a non-list. */ - fun removeMemberPermissions(): Optional> = - Optional.ofNullable(removeMemberPermissions.getNullable("remove_member_permissions")) + fun addAddMemberRole(addMemberRole: String) = apply { body.addAddMemberRole(addMemberRole) } + + /** Textual description of the role */ + fun description(description: String?) = apply { body.description(description) } + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) /** - * A list of role IDs to remove from the role's inheriting-from set + * Sets [Builder.description] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun removeMemberRoles(): Optional> = - Optional.ofNullable(removeMemberRoles.getNullable("remove_member_roles")) + fun description(description: JsonField) = apply { body.description(description) } + + /** Name of the role */ + fun name(name: String?) = apply { body.name(name) } + + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) /** - * Returns the raw JSON value of [addMemberPermissions]. + * Sets [Builder.name] to an arbitrary JSON value. * - * Unlike [addMemberPermissions], this method doesn't throw if the JSON field has an - * unexpected type. + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("add_member_permissions") - @ExcludeMissing - fun _addMemberPermissions(): JsonField> = addMemberPermissions + fun name(name: JsonField) = apply { body.name(name) } + + /** A list of permissions to remove from the role */ + fun removeMemberPermissions(removeMemberPermissions: List?) = + apply { + body.removeMemberPermissions(removeMemberPermissions) + } /** - * Returns the raw JSON value of [addMemberRoles]. - * - * Unlike [addMemberRoles], this method doesn't throw if the JSON field has an unexpected - * type. + * Alias for calling [Builder.removeMemberPermissions] with + * `removeMemberPermissions.orElse(null)`. */ - @JsonProperty("add_member_roles") - @ExcludeMissing - fun _addMemberRoles(): JsonField> = addMemberRoles + fun removeMemberPermissions( + removeMemberPermissions: Optional> + ) = removeMemberPermissions(removeMemberPermissions.getOrNull()) /** - * Returns the raw JSON value of [description]. + * Sets [Builder.removeMemberPermissions] to an arbitrary JSON value. * - * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.removeMemberPermissions] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. */ - @JsonProperty("description") - @ExcludeMissing - fun _description(): JsonField = description + fun removeMemberPermissions( + removeMemberPermissions: JsonField> + ) = apply { body.removeMemberPermissions(removeMemberPermissions) } /** - * Returns the raw JSON value of [name]. + * Adds a single [RemoveMemberPermission] to [removeMemberPermissions]. * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + * @throws IllegalStateException if the field was previously set to a non-list. */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + fun addRemoveMemberPermission(removeMemberPermission: RemoveMemberPermission) = apply { + body.addRemoveMemberPermission(removeMemberPermission) + } + + /** A list of role IDs to remove from the role's inheriting-from set */ + fun removeMemberRoles(removeMemberRoles: List?) = apply { + body.removeMemberRoles(removeMemberRoles) + } + + /** Alias for calling [Builder.removeMemberRoles] with `removeMemberRoles.orElse(null)`. */ + fun removeMemberRoles(removeMemberRoles: Optional>) = + removeMemberRoles(removeMemberRoles.getOrNull()) /** - * Returns the raw JSON value of [removeMemberPermissions]. + * Sets [Builder.removeMemberRoles] to an arbitrary JSON value. * - * Unlike [removeMemberPermissions], this method doesn't throw if the JSON field has an - * unexpected type. + * You should usually call [Builder.removeMemberRoles] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. */ - @JsonProperty("remove_member_permissions") - @ExcludeMissing - fun _removeMemberPermissions(): JsonField> = - removeMemberPermissions + fun removeMemberRoles(removeMemberRoles: JsonField>) = apply { + body.removeMemberRoles(removeMemberRoles) + } /** - * Returns the raw JSON value of [removeMemberRoles]. + * Adds a single [String] to [removeMemberRoles]. * - * Unlike [removeMemberRoles], this method doesn't throw if the JSON field has an unexpected - * type. + * @throws IllegalStateException if the field was previously set to a non-list. */ - @JsonProperty("remove_member_roles") - @ExcludeMissing - fun _removeMemberRoles(): JsonField> = removeMemberRoles - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false + fun addRemoveMemberRole(removeMemberRole: String) = apply { + body.addRemoveMemberRole(removeMemberRole) + } - fun validate(): Body = apply { - if (validated) { - return@apply - } + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } - addMemberPermissions().ifPresent { it.forEach { it.validate() } } - addMemberRoles() - description() - name() - removeMemberPermissions().ifPresent { it.forEach { it.validate() } } - removeMemberRoles() - validated = true + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) } - fun toBuilder() = Builder().from(this) + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } - companion object { + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - /** Returns a mutable builder for constructing an instance of [Body]. */ - @JvmStatic fun builder() = Builder() + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) } - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var addMemberPermissions: JsonField>? = null - private var addMemberRoles: JsonField>? = null - private var description: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var removeMemberPermissions: JsonField>? = - null - private var removeMemberRoles: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - addMemberPermissions = body.addMemberPermissions.map { it.toMutableList() } - addMemberRoles = body.addMemberRoles.map { it.toMutableList() } - description = body.description - name = body.name - removeMemberPermissions = body.removeMemberPermissions.map { it.toMutableList() } - removeMemberRoles = body.removeMemberRoles.map { it.toMutableList() } - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** A list of permissions to add to the role */ - fun addMemberPermissions(addMemberPermissions: List?) = - addMemberPermissions(JsonField.ofNullable(addMemberPermissions)) - - /** - * Alias for calling [Builder.addMemberPermissions] with - * `addMemberPermissions.orElse(null)`. - */ - fun addMemberPermissions(addMemberPermissions: Optional>) = - addMemberPermissions(addMemberPermissions.getOrNull()) - - /** - * Sets [Builder.addMemberPermissions] to an arbitrary JSON value. - * - * You should usually call [Builder.addMemberPermissions] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun addMemberPermissions(addMemberPermissions: JsonField>) = - apply { - this.addMemberPermissions = addMemberPermissions.map { it.toMutableList() } - } - - /** - * Adds a single [AddMemberPermission] to [addMemberPermissions]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addAddMemberPermission(addMemberPermission: AddMemberPermission) = apply { - addMemberPermissions = - (addMemberPermissions ?: JsonField.of(mutableListOf())).also { - checkKnown("addMemberPermissions", it).add(addMemberPermission) - } - } - - /** A list of role IDs to add to the role's inheriting-from set */ - fun addMemberRoles(addMemberRoles: List?) = - addMemberRoles(JsonField.ofNullable(addMemberRoles)) - - /** Alias for calling [Builder.addMemberRoles] with `addMemberRoles.orElse(null)`. */ - fun addMemberRoles(addMemberRoles: Optional>) = - addMemberRoles(addMemberRoles.getOrNull()) - - /** - * Sets [Builder.addMemberRoles] to an arbitrary JSON value. - * - * You should usually call [Builder.addMemberRoles] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun addMemberRoles(addMemberRoles: JsonField>) = apply { - this.addMemberRoles = addMemberRoles.map { it.toMutableList() } - } - - /** - * Adds a single [String] to [addMemberRoles]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addAddMemberRole(addMemberRole: String) = apply { - addMemberRoles = - (addMemberRoles ?: JsonField.of(mutableListOf())).also { - checkKnown("addMemberRoles", it).add(addMemberRole) - } - } - - /** Textual description of the role */ - fun description(description: String?) = description(JsonField.ofNullable(description)) - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) - - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun description(description: JsonField) = apply { - this.description = description - } - - /** Name of the role */ - fun name(name: String?) = name(JsonField.ofNullable(name)) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** Alias for calling [Builder.name] with `name.orElse(null)`. */ - fun name(name: Optional) = name(name.getOrNull()) + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } - /** A list of permissions to remove from the role */ - fun removeMemberPermissions(removeMemberPermissions: List?) = - removeMemberPermissions(JsonField.ofNullable(removeMemberPermissions)) + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - /** - * Alias for calling [Builder.removeMemberPermissions] with - * `removeMemberPermissions.orElse(null)`. - */ - fun removeMemberPermissions( - removeMemberPermissions: Optional> - ) = removeMemberPermissions(removeMemberPermissions.getOrNull()) + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** - * Sets [Builder.removeMemberPermissions] to an arbitrary JSON value. - * - * You should usually call [Builder.removeMemberPermissions] with a well-typed - * `List` value instead. This method is primarily for setting - * the field to an undocumented or not yet supported value. - */ - fun removeMemberPermissions( - removeMemberPermissions: JsonField> - ) = apply { - this.removeMemberPermissions = removeMemberPermissions.map { it.toMutableList() } - } + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** - * Adds a single [RemoveMemberPermission] to [removeMemberPermissions]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addRemoveMemberPermission(removeMemberPermission: RemoveMemberPermission) = apply { - removeMemberPermissions = - (removeMemberPermissions ?: JsonField.of(mutableListOf())).also { - checkKnown("removeMemberPermissions", it).add(removeMemberPermission) - } - } + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - /** A list of role IDs to remove from the role's inheriting-from set */ - fun removeMemberRoles(removeMemberRoles: List?) = - removeMemberRoles(JsonField.ofNullable(removeMemberRoles)) + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** - * Alias for calling [Builder.removeMemberRoles] with `removeMemberRoles.orElse(null)`. - */ - fun removeMemberRoles(removeMemberRoles: Optional>) = - removeMemberRoles(removeMemberRoles.getOrNull()) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Sets [Builder.removeMemberRoles] to an arbitrary JSON value. - * - * You should usually call [Builder.removeMemberRoles] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun removeMemberRoles(removeMemberRoles: JsonField>) = apply { - this.removeMemberRoles = removeMemberRoles.map { it.toMutableList() } - } + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Adds a single [String] to [removeMemberRoles]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addRemoveMemberRole(removeMemberRole: String) = apply { - removeMemberRoles = - (removeMemberRoles ?: JsonField.of(mutableListOf())).also { - checkKnown("removeMemberRoles", it).add(removeMemberRole) - } - } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Body = - Body( - (addMemberPermissions ?: JsonMissing.of()).map { it.toImmutable() }, - (addMemberRoles ?: JsonMissing.of()).map { it.toImmutable() }, - description, - name, - (removeMemberPermissions ?: JsonMissing.of()).map { it.toImmutable() }, - (removeMemberRoles ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), - ) + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - return /* spotless:off */ other is Body && addMemberPermissions == other.addMemberPermissions && addMemberRoles == other.addMemberRoles && description == other.description && name == other.name && removeMemberPermissions == other.removeMemberPermissions && removeMemberRoles == other.removeMemberRoles && additionalProperties == other.additionalProperties /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(addMemberPermissions, addMemberRoles, description, name, removeMemberPermissions, removeMemberRoles, additionalProperties) } - /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } - override fun hashCode(): Int = hashCode + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - override fun toString() = - "Body{addMemberPermissions=$addMemberPermissions, addMemberRoles=$addMemberRoles, description=$description, name=$name, removeMemberPermissions=$removeMemberPermissions, removeMemberRoles=$removeMemberRoles, additionalProperties=$additionalProperties}" - } + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - fun toBuilder() = Builder().from(this) + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - companion object { + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } /** - * Returns a mutable builder for constructing an instance of [RoleUpdateParams]. + * Returns an immutable instance of [RoleUpdateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java * .roleId() * ``` + * + * @throws IllegalStateException if any required field is unset. */ - @JvmStatic fun builder() = Builder() + fun build(): RoleUpdateParams = + RoleUpdateParams( + checkRequired("roleId", roleId), + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) } - /** A builder for [RoleUpdateParams]. */ - @NoAutoDetect - class Builder internal constructor() { - - private var roleId: String? = null - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + @JvmSynthetic internal fun _body(): Body = body - @JvmSynthetic - internal fun from(roleUpdateParams: RoleUpdateParams) = apply { - roleId = roleUpdateParams.roleId - body = roleUpdateParams.body.toBuilder() - additionalHeaders = roleUpdateParams.additionalHeaders.toBuilder() - additionalQueryParams = roleUpdateParams.additionalQueryParams.toBuilder() + fun _pathParam(index: Int): String = + when (index) { + 0 -> roleId + else -> "" } - /** Role id */ - fun roleId(roleId: String) = apply { this.roleId = roleId } + override fun _headers(): Headers = additionalHeaders - /** A list of permissions to add to the role */ - fun addMemberPermissions(addMemberPermissions: List?) = apply { - body.addMemberPermissions(addMemberPermissions) - } + override fun _queryParams(): QueryParams = additionalQueryParams - /** - * Alias for calling [Builder.addMemberPermissions] with - * `addMemberPermissions.orElse(null)`. - */ - fun addMemberPermissions(addMemberPermissions: Optional>) = - addMemberPermissions(addMemberPermissions.getOrNull()) + class Body + private constructor( + private val addMemberPermissions: JsonField>, + private val addMemberRoles: JsonField>, + private val description: JsonField, + private val name: JsonField, + private val removeMemberPermissions: JsonField>, + private val removeMemberRoles: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("add_member_permissions") + @ExcludeMissing + addMemberPermissions: JsonField> = JsonMissing.of(), + @JsonProperty("add_member_roles") + @ExcludeMissing + addMemberRoles: JsonField> = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("remove_member_permissions") + @ExcludeMissing + removeMemberPermissions: JsonField> = JsonMissing.of(), + @JsonProperty("remove_member_roles") + @ExcludeMissing + removeMemberRoles: JsonField> = JsonMissing.of(), + ) : this( + addMemberPermissions, + addMemberRoles, + description, + name, + removeMemberPermissions, + removeMemberRoles, + mutableMapOf(), + ) /** - * Sets [Builder.addMemberPermissions] to an arbitrary JSON value. + * A list of permissions to add to the role * - * You should usually call [Builder.addMemberPermissions] with a well-typed - * `List` value instead. This method is primarily for setting the field - * to an undocumented or not yet supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun addMemberPermissions(addMemberPermissions: JsonField>) = - apply { - body.addMemberPermissions(addMemberPermissions) - } + fun addMemberPermissions(): Optional> = + Optional.ofNullable(addMemberPermissions.getNullable("add_member_permissions")) /** - * Adds a single [AddMemberPermission] to [addMemberPermissions]. + * A list of role IDs to add to the role's inheriting-from set * - * @throws IllegalStateException if the field was previously set to a non-list. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun addAddMemberPermission(addMemberPermission: AddMemberPermission) = apply { - body.addAddMemberPermission(addMemberPermission) - } - - /** A list of role IDs to add to the role's inheriting-from set */ - fun addMemberRoles(addMemberRoles: List?) = apply { - body.addMemberRoles(addMemberRoles) - } - - /** Alias for calling [Builder.addMemberRoles] with `addMemberRoles.orElse(null)`. */ - fun addMemberRoles(addMemberRoles: Optional>) = - addMemberRoles(addMemberRoles.getOrNull()) + fun addMemberRoles(): Optional> = + Optional.ofNullable(addMemberRoles.getNullable("add_member_roles")) /** - * Sets [Builder.addMemberRoles] to an arbitrary JSON value. + * Textual description of the role * - * You should usually call [Builder.addMemberRoles] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun addMemberRoles(addMemberRoles: JsonField>) = apply { - body.addMemberRoles(addMemberRoles) - } + fun description(): Optional = + Optional.ofNullable(description.getNullable("description")) /** - * Adds a single [String] to [addMemberRoles]. + * Name of the role * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addAddMemberRole(addMemberRole: String) = apply { body.addAddMemberRole(addMemberRole) } - - /** Textual description of the role */ - fun description(description: String?) = apply { body.description(description) } - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) /** - * Sets [Builder.description] to an arbitrary JSON value. + * A list of permissions to remove from the role * - * You should usually call [Builder.description] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun description(description: JsonField) = apply { body.description(description) } - - /** Name of the role */ - fun name(name: String?) = apply { body.name(name) } - - /** Alias for calling [Builder.name] with `name.orElse(null)`. */ - fun name(name: Optional) = name(name.getOrNull()) + fun removeMemberPermissions(): Optional> = + Optional.ofNullable(removeMemberPermissions.getNullable("remove_member_permissions")) /** - * Sets [Builder.name] to an arbitrary JSON value. + * A list of role IDs to remove from the role's inheriting-from set * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun name(name: JsonField) = apply { body.name(name) } - - /** A list of permissions to remove from the role */ - fun removeMemberPermissions(removeMemberPermissions: List?) = - apply { - body.removeMemberPermissions(removeMemberPermissions) - } + fun removeMemberRoles(): Optional> = + Optional.ofNullable(removeMemberRoles.getNullable("remove_member_roles")) /** - * Alias for calling [Builder.removeMemberPermissions] with - * `removeMemberPermissions.orElse(null)`. + * Returns the raw JSON value of [addMemberPermissions]. + * + * Unlike [addMemberPermissions], this method doesn't throw if the JSON field has an + * unexpected type. */ - fun removeMemberPermissions( - removeMemberPermissions: Optional> - ) = removeMemberPermissions(removeMemberPermissions.getOrNull()) + @JsonProperty("add_member_permissions") + @ExcludeMissing + fun _addMemberPermissions(): JsonField> = addMemberPermissions /** - * Sets [Builder.removeMemberPermissions] to an arbitrary JSON value. + * Returns the raw JSON value of [addMemberRoles]. * - * You should usually call [Builder.removeMemberPermissions] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. + * Unlike [addMemberRoles], this method doesn't throw if the JSON field has an unexpected + * type. */ - fun removeMemberPermissions( - removeMemberPermissions: JsonField> - ) = apply { body.removeMemberPermissions(removeMemberPermissions) } + @JsonProperty("add_member_roles") + @ExcludeMissing + fun _addMemberRoles(): JsonField> = addMemberRoles /** - * Adds a single [RemoveMemberPermission] to [removeMemberPermissions]. + * Returns the raw JSON value of [description]. * - * @throws IllegalStateException if the field was previously set to a non-list. + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. */ - fun addRemoveMemberPermission(removeMemberPermission: RemoveMemberPermission) = apply { - body.addRemoveMemberPermission(removeMemberPermission) - } - - /** A list of role IDs to remove from the role's inheriting-from set */ - fun removeMemberRoles(removeMemberRoles: List?) = apply { - body.removeMemberRoles(removeMemberRoles) - } + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description - /** Alias for calling [Builder.removeMemberRoles] with `removeMemberRoles.orElse(null)`. */ - fun removeMemberRoles(removeMemberRoles: Optional>) = - removeMemberRoles(removeMemberRoles.getOrNull()) + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name /** - * Sets [Builder.removeMemberRoles] to an arbitrary JSON value. + * Returns the raw JSON value of [removeMemberPermissions]. * - * You should usually call [Builder.removeMemberRoles] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * Unlike [removeMemberPermissions], this method doesn't throw if the JSON field has an + * unexpected type. */ - fun removeMemberRoles(removeMemberRoles: JsonField>) = apply { - body.removeMemberRoles(removeMemberRoles) - } + @JsonProperty("remove_member_permissions") + @ExcludeMissing + fun _removeMemberPermissions(): JsonField> = + removeMemberPermissions /** - * Adds a single [String] to [removeMemberRoles]. + * Returns the raw JSON value of [removeMemberRoles]. * - * @throws IllegalStateException if the field was previously set to a non-list. + * Unlike [removeMemberRoles], this method doesn't throw if the JSON field has an unexpected + * type. */ - fun addRemoveMemberRole(removeMemberRole: String) = apply { - body.addRemoveMemberRole(removeMemberRole) - } + @JsonProperty("remove_member_roles") + @ExcludeMissing + fun _removeMemberRoles(): JsonField> = removeMemberRoles - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Body]. */ + @JvmStatic fun builder() = Builder() } - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var addMemberPermissions: JsonField>? = null + private var addMemberRoles: JsonField>? = null + private var description: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var removeMemberPermissions: JsonField>? = + null + private var removeMemberRoles: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + addMemberPermissions = body.addMemberPermissions.map { it.toMutableList() } + addMemberRoles = body.addMemberRoles.map { it.toMutableList() } + description = body.description + name = body.name + removeMemberPermissions = body.removeMemberPermissions.map { it.toMutableList() } + removeMemberRoles = body.removeMemberRoles.map { it.toMutableList() } + additionalProperties = body.additionalProperties.toMutableMap() } - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + /** A list of permissions to add to the role */ + fun addMemberPermissions(addMemberPermissions: List?) = + addMemberPermissions(JsonField.ofNullable(addMemberPermissions)) - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } + /** + * Alias for calling [Builder.addMemberPermissions] with + * `addMemberPermissions.orElse(null)`. + */ + fun addMemberPermissions(addMemberPermissions: Optional>) = + addMemberPermissions(addMemberPermissions.getOrNull()) - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * Sets [Builder.addMemberPermissions] to an arbitrary JSON value. + * + * You should usually call [Builder.addMemberPermissions] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun addMemberPermissions(addMemberPermissions: JsonField>) = + apply { + this.addMemberPermissions = addMemberPermissions.map { it.toMutableList() } + } - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * Adds a single [AddMemberPermission] to [addMemberPermissions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAddMemberPermission(addMemberPermission: AddMemberPermission) = apply { + addMemberPermissions = + (addMemberPermissions ?: JsonField.of(mutableListOf())).also { + checkKnown("addMemberPermissions", it).add(addMemberPermission) + } + } - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } + /** A list of role IDs to add to the role's inheriting-from set */ + fun addMemberRoles(addMemberRoles: List?) = + addMemberRoles(JsonField.ofNullable(addMemberRoles)) + + /** Alias for calling [Builder.addMemberRoles] with `addMemberRoles.orElse(null)`. */ + fun addMemberRoles(addMemberRoles: Optional>) = + addMemberRoles(addMemberRoles.getOrNull()) + + /** + * Sets [Builder.addMemberRoles] to an arbitrary JSON value. + * + * You should usually call [Builder.addMemberRoles] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun addMemberRoles(addMemberRoles: JsonField>) = apply { + this.addMemberRoles = addMemberRoles.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [addMemberRoles]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAddMemberRole(addMemberRole: String) = apply { + addMemberRoles = + (addMemberRoles ?: JsonField.of(mutableListOf())).also { + checkKnown("addMemberRoles", it).add(addMemberRole) + } + } + + /** Textual description of the role */ + fun description(description: String?) = description(JsonField.ofNullable(description)) + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } + + /** Name of the role */ + fun name(name: String?) = name(JsonField.ofNullable(name)) + + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** A list of permissions to remove from the role */ + fun removeMemberPermissions(removeMemberPermissions: List?) = + removeMemberPermissions(JsonField.ofNullable(removeMemberPermissions)) - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } + /** + * Alias for calling [Builder.removeMemberPermissions] with + * `removeMemberPermissions.orElse(null)`. + */ + fun removeMemberPermissions( + removeMemberPermissions: Optional> + ) = removeMemberPermissions(removeMemberPermissions.getOrNull()) - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** + * Sets [Builder.removeMemberPermissions] to an arbitrary JSON value. + * + * You should usually call [Builder.removeMemberPermissions] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun removeMemberPermissions( + removeMemberPermissions: JsonField> + ) = apply { + this.removeMemberPermissions = removeMemberPermissions.map { it.toMutableList() } + } - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** + * Adds a single [RemoveMemberPermission] to [removeMemberPermissions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRemoveMemberPermission(removeMemberPermission: RemoveMemberPermission) = apply { + removeMemberPermissions = + (removeMemberPermissions ?: JsonField.of(mutableListOf())).also { + checkKnown("removeMemberPermissions", it).add(removeMemberPermission) + } + } - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } + /** A list of role IDs to remove from the role's inheriting-from set */ + fun removeMemberRoles(removeMemberRoles: List?) = + removeMemberRoles(JsonField.ofNullable(removeMemberRoles)) - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } + /** + * Alias for calling [Builder.removeMemberRoles] with `removeMemberRoles.orElse(null)`. + */ + fun removeMemberRoles(removeMemberRoles: Optional>) = + removeMemberRoles(removeMemberRoles.getOrNull()) - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** + * Sets [Builder.removeMemberRoles] to an arbitrary JSON value. + * + * You should usually call [Builder.removeMemberRoles] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun removeMemberRoles(removeMemberRoles: JsonField>) = apply { + this.removeMemberRoles = removeMemberRoles.map { it.toMutableList() } + } - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** + * Adds a single [String] to [removeMemberRoles]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRemoveMemberRole(removeMemberRole: String) = apply { + removeMemberRoles = + (removeMemberRoles ?: JsonField.of(mutableListOf())).also { + checkKnown("removeMemberRoles", it).add(removeMemberRole) + } + } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Body = + Body( + (addMemberPermissions ?: JsonMissing.of()).map { it.toImmutable() }, + (addMemberRoles ?: JsonMissing.of()).map { it.toImmutable() }, + description, + name, + (removeMemberPermissions ?: JsonMissing.of()).map { it.toImmutable() }, + (removeMemberRoles ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } + private var validated: Boolean = false - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + fun validate(): Body = apply { + if (validated) { + return@apply } - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) + addMemberPermissions().ifPresent { it.forEach { it.validate() } } + addMemberRoles() + description() + name() + removeMemberPermissions().ifPresent { it.forEach { it.validate() } } + removeMemberRoles() + validated = true } - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + return /* spotless:off */ other is Body && addMemberPermissions == other.addMemberPermissions && addMemberRoles == other.addMemberRoles && description == other.description && name == other.name && removeMemberPermissions == other.removeMemberPermissions && removeMemberRoles == other.removeMemberRoles && additionalProperties == other.additionalProperties /* spotless:on */ } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) - } - - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(addMemberPermissions, addMemberRoles, description, name, removeMemberPermissions, removeMemberRoles, additionalProperties) } + /* spotless:on */ - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) - } + override fun hashCode(): Int = hashCode - /** - * Returns an immutable instance of [RoleUpdateParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .roleId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): RoleUpdateParams = - RoleUpdateParams( - checkRequired("roleId", roleId), - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + override fun toString() = + "Body{addMemberPermissions=$addMemberPermissions, addMemberRoles=$addMemberRoles, description=$description, name=$name, removeMemberPermissions=$removeMemberPermissions, removeMemberRoles=$removeMemberRoles, additionalProperties=$additionalProperties}" } - @NoAutoDetect class AddMemberPermission - @JsonCreator private constructor( - @JsonProperty("permission") - @ExcludeMissing - private val permission: JsonField = JsonMissing.of(), - @JsonProperty("restrict_object_type") - @ExcludeMissing - private val restrictObjectType: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val permission: JsonField, + private val restrictObjectType: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("permission") + @ExcludeMissing + permission: JsonField = JsonMissing.of(), + @JsonProperty("restrict_object_type") + @ExcludeMissing + restrictObjectType: JsonField = JsonMissing.of(), + ) : this(permission, restrictObjectType, mutableMapOf()) + /** * Each permission permits a certain type of operation on an object in the system * @@ -939,21 +958,15 @@ private constructor( @ExcludeMissing fun _restrictObjectType(): JsonField = restrictObjectType + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): AddMemberPermission = apply { - if (validated) { - return@apply - } - - permission() - restrictObjectType() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1060,10 +1073,22 @@ private constructor( AddMemberPermission( checkRequired("permission", permission), restrictObjectType, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): AddMemberPermission = apply { + if (validated) { + return@apply + } + + permission() + restrictObjectType() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1082,20 +1107,23 @@ private constructor( "AddMemberPermission{permission=$permission, restrictObjectType=$restrictObjectType, additionalProperties=$additionalProperties}" } - @NoAutoDetect class RemoveMemberPermission - @JsonCreator private constructor( - @JsonProperty("permission") - @ExcludeMissing - private val permission: JsonField = JsonMissing.of(), - @JsonProperty("restrict_object_type") - @ExcludeMissing - private val restrictObjectType: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val permission: JsonField, + private val restrictObjectType: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("permission") + @ExcludeMissing + permission: JsonField = JsonMissing.of(), + @JsonProperty("restrict_object_type") + @ExcludeMissing + restrictObjectType: JsonField = JsonMissing.of(), + ) : this(permission, restrictObjectType, mutableMapOf()) + /** * Each permission permits a certain type of operation on an object in the system * @@ -1134,21 +1162,15 @@ private constructor( @ExcludeMissing fun _restrictObjectType(): JsonField = restrictObjectType + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): RemoveMemberPermission = apply { - if (validated) { - return@apply - } - - permission() - restrictObjectType() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1255,10 +1277,22 @@ private constructor( RemoveMemberPermission( checkRequired("permission", permission), restrictObjectType, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): RemoveMemberPermission = apply { + if (validated) { + return@apply + } + + permission() + restrictObjectType() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ScoreSummary.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ScoreSummary.kt index 2d7c5189..b74de965 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ScoreSummary.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ScoreSummary.kt @@ -6,35 +6,40 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional /** Summary of a score's performance */ -@NoAutoDetect class ScoreSummary -@JsonCreator private constructor( - @JsonProperty("improvements") - @ExcludeMissing - private val improvements: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing private val name: JsonField = JsonMissing.of(), - @JsonProperty("regressions") - @ExcludeMissing - private val regressions: JsonField = JsonMissing.of(), - @JsonProperty("score") @ExcludeMissing private val score: JsonField = JsonMissing.of(), - @JsonProperty("diff") @ExcludeMissing private val diff: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val improvements: JsonField, + private val name: JsonField, + private val regressions: JsonField, + private val score: JsonField, + private val diff: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("improvements") + @ExcludeMissing + improvements: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("regressions") + @ExcludeMissing + regressions: JsonField = JsonMissing.of(), + @JsonProperty("score") @ExcludeMissing score: JsonField = JsonMissing.of(), + @JsonProperty("diff") @ExcludeMissing diff: JsonField = JsonMissing.of(), + ) : this(improvements, name, regressions, score, diff, mutableMapOf()) + /** * Number of improvements in the score * @@ -112,24 +117,15 @@ private constructor( */ @JsonProperty("diff") @ExcludeMissing fun _diff(): JsonField = diff + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): ScoreSummary = apply { - if (validated) { - return@apply - } - - improvements() - name() - regressions() - score() - diff() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -267,10 +263,25 @@ private constructor( checkRequired("regressions", regressions), checkRequired("score", score), diff, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): ScoreSummary = apply { + if (validated) { + return@apply + } + + improvements() + name() + regressions() + score() + diff() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanAttributes.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanAttributes.kt index 68f8d827..b0d8307a 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanAttributes.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanAttributes.kt @@ -6,28 +6,30 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Human-identifying attributes of the span, such as name, type, etc. */ -@NoAutoDetect class SpanAttributes -@JsonCreator private constructor( - @JsonProperty("name") @ExcludeMissing private val name: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing private val type: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val name: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(name, type, mutableMapOf()) + /** * Name of the span, for display purposes only * @@ -58,21 +60,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): SpanAttributes = apply { - if (validated) { - return@apply - } - - name() - type() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -148,7 +144,20 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): SpanAttributes = SpanAttributes(name, type, additionalProperties.toImmutable()) + fun build(): SpanAttributes = + SpanAttributes(name, type, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): SpanAttributes = apply { + if (validated) { + return@apply + } + + name() + type() + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIFrame.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIFrame.kt index bd4d2359..cb222f2c 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIFrame.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIFrame.kt @@ -6,48 +6,64 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class SpanIFrame -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing private val name: JsonField = JsonMissing.of(), - @JsonProperty("project_id") - @ExcludeMissing - private val projectId: JsonField = JsonMissing.of(), - @JsonProperty("url") @ExcludeMissing private val url: JsonField = JsonMissing.of(), - @JsonProperty("created") - @ExcludeMissing - private val created: JsonField = JsonMissing.of(), - @JsonProperty("deleted_at") - @ExcludeMissing - private val deletedAt: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("post_message") - @ExcludeMissing - private val postMessage: JsonField = JsonMissing.of(), - @JsonProperty("user_id") - @ExcludeMissing - private val userId: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val name: JsonField, + private val projectId: JsonField, + private val url: JsonField, + private val created: JsonField, + private val deletedAt: JsonField, + private val description: JsonField, + private val postMessage: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("project_id") @ExcludeMissing projectId: JsonField = JsonMissing.of(), + @JsonProperty("url") @ExcludeMissing url: JsonField = JsonMissing.of(), + @JsonProperty("created") + @ExcludeMissing + created: JsonField = JsonMissing.of(), + @JsonProperty("deleted_at") + @ExcludeMissing + deletedAt: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("post_message") + @ExcludeMissing + postMessage: JsonField = JsonMissing.of(), + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), + ) : this( + id, + name, + projectId, + url, + created, + deletedAt, + description, + postMessage, + userId, + mutableMapOf(), + ) + /** * Unique identifier for the span iframe * @@ -191,28 +207,15 @@ private constructor( */ @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): SpanIFrame = apply { - if (validated) { - return@apply - } - - id() - name() - projectId() - url() - created() - deletedAt() - description() - postMessage() - userId() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -434,10 +437,29 @@ private constructor( description, postMessage, userId, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): SpanIFrame = apply { + if (validated) { + return@apply + } + + id() + name() + projectId() + url() + created() + deletedAt() + description() + postMessage() + userId() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeCreateParams.kt index 6883efec..ba9059c9 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeCreateParams.kt @@ -6,18 +6,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -115,33 +113,281 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [SpanIframeCreateParams]. + * + * The following fields are required: + * ```java + * .name() + * .projectId() + * .url() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpanIframeCreateParams]. */ + class Builder internal constructor() { + + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(spanIframeCreateParams: SpanIframeCreateParams) = apply { + body = spanIframeCreateParams.body.toBuilder() + additionalHeaders = spanIframeCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = spanIframeCreateParams.additionalQueryParams.toBuilder() + } + + /** Name of the span iframe */ + fun name(name: String) = apply { body.name(name) } + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { body.name(name) } + + /** Unique identifier for the project that the span iframe belongs under */ + fun projectId(projectId: String) = apply { body.projectId(projectId) } + + /** + * Sets [Builder.projectId] to an arbitrary JSON value. + * + * You should usually call [Builder.projectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun projectId(projectId: JsonField) = apply { body.projectId(projectId) } + + /** URL to embed the project viewer in an iframe */ + fun url(url: String) = apply { body.url(url) } + + /** + * Sets [Builder.url] to an arbitrary JSON value. + * + * You should usually call [Builder.url] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun url(url: JsonField) = apply { body.url(url) } + + /** Textual description of the span iframe */ + fun description(description: String?) = apply { body.description(description) } + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun description(description: JsonField) = apply { body.description(description) } + + /** + * Whether to post messages to the iframe containing the span's data. This is useful when + * you want to render more data than fits in the URL. + */ + fun postMessage(postMessage: Boolean?) = apply { body.postMessage(postMessage) } + + /** + * Alias for [Builder.postMessage]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun postMessage(postMessage: Boolean) = postMessage(postMessage as Boolean?) + + /** Alias for calling [Builder.postMessage] with `postMessage.orElse(null)`. */ + fun postMessage(postMessage: Optional) = postMessage(postMessage.getOrNull()) + + /** + * Sets [Builder.postMessage] to an arbitrary JSON value. + * + * You should usually call [Builder.postMessage] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun postMessage(postMessage: JsonField) = apply { body.postMessage(postMessage) } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(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 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) + } + + /** + * Returns an immutable instance of [SpanIframeCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * .projectId() + * .url() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpanIframeCreateParams = + SpanIframeCreateParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + @JvmSynthetic internal fun _body(): Body = body override fun _headers(): Headers = additionalHeaders override fun _queryParams(): QueryParams = additionalQueryParams - @NoAutoDetect class Body - @JsonCreator private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("project_id") - @ExcludeMissing - private val projectId: JsonField = JsonMissing.of(), - @JsonProperty("url") @ExcludeMissing private val url: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("post_message") - @ExcludeMissing - private val postMessage: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val name: JsonField, + private val projectId: JsonField, + private val url: JsonField, + private val description: JsonField, + private val postMessage: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("url") @ExcludeMissing url: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("post_message") + @ExcludeMissing + postMessage: JsonField = JsonMissing.of(), + ) : this(name, projectId, url, description, postMessage, mutableMapOf()) + /** * Name of the span iframe * @@ -224,24 +470,15 @@ private constructor( @ExcludeMissing fun _postMessage(): JsonField = postMessage + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } - - name() - projectId() - url() - description() - postMessage() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -400,10 +637,25 @@ private constructor( checkRequired("url", url), description, postMessage, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + name() + projectId() + url() + description() + postMessage() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -422,251 +674,6 @@ private constructor( "Body{name=$name, projectId=$projectId, url=$url, description=$description, postMessage=$postMessage, additionalProperties=$additionalProperties}" } - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [SpanIframeCreateParams]. - * - * The following fields are required: - * ```java - * .name() - * .projectId() - * .url() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [SpanIframeCreateParams]. */ - @NoAutoDetect - class Builder internal constructor() { - - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - - @JvmSynthetic - internal fun from(spanIframeCreateParams: SpanIframeCreateParams) = apply { - body = spanIframeCreateParams.body.toBuilder() - additionalHeaders = spanIframeCreateParams.additionalHeaders.toBuilder() - additionalQueryParams = spanIframeCreateParams.additionalQueryParams.toBuilder() - } - - /** Name of the span iframe */ - fun name(name: String) = apply { body.name(name) } - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun name(name: JsonField) = apply { body.name(name) } - - /** Unique identifier for the project that the span iframe belongs under */ - fun projectId(projectId: String) = apply { body.projectId(projectId) } - - /** - * Sets [Builder.projectId] to an arbitrary JSON value. - * - * You should usually call [Builder.projectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun projectId(projectId: JsonField) = apply { body.projectId(projectId) } - - /** URL to embed the project viewer in an iframe */ - fun url(url: String) = apply { body.url(url) } - - /** - * Sets [Builder.url] to an arbitrary JSON value. - * - * You should usually call [Builder.url] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun url(url: JsonField) = apply { body.url(url) } - - /** Textual description of the span iframe */ - fun description(description: String?) = apply { body.description(description) } - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) - - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun description(description: JsonField) = apply { body.description(description) } - - /** - * Whether to post messages to the iframe containing the span's data. This is useful when - * you want to render more data than fits in the URL. - */ - fun postMessage(postMessage: Boolean?) = apply { body.postMessage(postMessage) } - - /** - * Alias for [Builder.postMessage]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun postMessage(postMessage: Boolean) = postMessage(postMessage as Boolean?) - - /** Alias for calling [Builder.postMessage] with `postMessage.orElse(null)`. */ - fun postMessage(postMessage: Optional) = postMessage(postMessage.getOrNull()) - - /** - * Sets [Builder.postMessage] to an arbitrary JSON value. - * - * You should usually call [Builder.postMessage] with a well-typed [Boolean] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun postMessage(postMessage: JsonField) = apply { body.postMessage(postMessage) } - - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) - } - - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } - - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) - } - - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } - - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } - - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } - - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(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 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) - } - - /** - * Returns an immutable instance of [SpanIframeCreateParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * .projectId() - * .url() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): SpanIframeCreateParams = - SpanIframeCreateParams( - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeDeleteParams.kt index 87082280..be2af662 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeDeleteParams.kt @@ -2,13 +2,15 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.toImmutable +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import java.util.Collections import java.util.Objects import java.util.Optional @@ -18,7 +20,7 @@ private constructor( private val spanIframeId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: Map, + private val additionalBodyProperties: MutableMap, ) : Params { /** SpanIframe id */ @@ -28,21 +30,15 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _additionalBodyProperties(): Map = additionalBodyProperties - - @JvmSynthetic - internal fun _body(): Optional> = - Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - - fun _pathParam(index: Int): String = - when (index) { - 0 -> spanIframeId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders + @JsonAnySetter + private fun putAdditionalBodyProperty(key: String, value: JsonValue) { + additionalBodyProperties.put(key, value) + } - override fun _queryParams(): QueryParams = additionalQueryParams + @JsonAnyGetter + @ExcludeMissing + fun _additionalBodyProperties(): Map = + Collections.unmodifiableMap(additionalBodyProperties) fun toBuilder() = Builder().from(this) @@ -60,7 +56,6 @@ private constructor( } /** A builder for [SpanIframeDeleteParams]. */ - @NoAutoDetect class Builder internal constructor() { private var spanIframeId: String? = null @@ -217,10 +212,24 @@ private constructor( checkRequired("spanIframeId", spanIframeId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toImmutable(), + additionalBodyProperties.toMutableMap(), ) } + @JvmSynthetic + internal fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> spanIframeId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt index 0018bcf6..b7e074d8 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.blocking.SpanIframeService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -90,24 +88,30 @@ private constructor( ) = SpanIframeListPage(spanIframesService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") - private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -165,7 +169,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt index b7d9bd94..8c067706 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.async.SpanIframeServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -92,24 +90,30 @@ private constructor( ) = SpanIframeListPageAsync(spanIframesService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") - private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -169,7 +173,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListParams.kt index fdfa8f86..36d6b9de 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListParams.kt @@ -5,7 +5,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.BaseDeserializer import com.braintrustdata.api.core.BaseSerializer import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers @@ -75,31 +74,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = - QueryParams.builder() - .apply { - endingBefore?.let { put("ending_before", it) } - ids?.accept( - object : Ids.Visitor { - override fun visitString(string: String) { - put("ids", string) - } - - override fun visitStrings(strings: List) { - put("ids", strings.joinToString(",")) - } - } - ) - limit?.let { put("limit", it.toString()) } - orgName?.let { put("org_name", it) } - spanIframeName?.let { put("span_iframe_name", it) } - startingAfter?.let { put("starting_after", it) } - putAll(additionalQueryParams) - } - .build() - fun toBuilder() = Builder().from(this) companion object { @@ -111,7 +85,6 @@ private constructor( } /** A builder for [SpanIframeListParams]. */ - @NoAutoDetect class Builder internal constructor() { private var endingBefore: String? = null @@ -317,6 +290,31 @@ private constructor( ) } + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + endingBefore?.let { put("ending_before", it) } + ids?.accept( + object : Ids.Visitor { + override fun visitString(string: String) { + put("ids", string) + } + + override fun visitStrings(strings: List) { + put("ids", strings.joinToString(",")) + } + } + ) + limit?.let { put("limit", it.toString()) } + orgName?.let { put("org_name", it) } + spanIframeName?.let { put("span_iframe_name", it) } + startingAfter?.let { put("starting_after", it) } + putAll(additionalQueryParams) + } + .build() + /** * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeReplaceParams.kt index 0b05cad8..f6375deb 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeReplaceParams.kt @@ -6,18 +6,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -115,33 +113,281 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [SpanIframeReplaceParams]. + * + * The following fields are required: + * ```java + * .name() + * .projectId() + * .url() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpanIframeReplaceParams]. */ + class Builder internal constructor() { + + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(spanIframeReplaceParams: SpanIframeReplaceParams) = apply { + body = spanIframeReplaceParams.body.toBuilder() + additionalHeaders = spanIframeReplaceParams.additionalHeaders.toBuilder() + additionalQueryParams = spanIframeReplaceParams.additionalQueryParams.toBuilder() + } + + /** Name of the span iframe */ + fun name(name: String) = apply { body.name(name) } + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { body.name(name) } + + /** Unique identifier for the project that the span iframe belongs under */ + fun projectId(projectId: String) = apply { body.projectId(projectId) } + + /** + * Sets [Builder.projectId] to an arbitrary JSON value. + * + * You should usually call [Builder.projectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun projectId(projectId: JsonField) = apply { body.projectId(projectId) } + + /** URL to embed the project viewer in an iframe */ + fun url(url: String) = apply { body.url(url) } + + /** + * Sets [Builder.url] to an arbitrary JSON value. + * + * You should usually call [Builder.url] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun url(url: JsonField) = apply { body.url(url) } + + /** Textual description of the span iframe */ + fun description(description: String?) = apply { body.description(description) } + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun description(description: JsonField) = apply { body.description(description) } + + /** + * Whether to post messages to the iframe containing the span's data. This is useful when + * you want to render more data than fits in the URL. + */ + fun postMessage(postMessage: Boolean?) = apply { body.postMessage(postMessage) } + + /** + * Alias for [Builder.postMessage]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun postMessage(postMessage: Boolean) = postMessage(postMessage as Boolean?) + + /** Alias for calling [Builder.postMessage] with `postMessage.orElse(null)`. */ + fun postMessage(postMessage: Optional) = postMessage(postMessage.getOrNull()) + + /** + * Sets [Builder.postMessage] to an arbitrary JSON value. + * + * You should usually call [Builder.postMessage] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun postMessage(postMessage: JsonField) = apply { body.postMessage(postMessage) } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(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 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) + } + + /** + * Returns an immutable instance of [SpanIframeReplaceParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * .projectId() + * .url() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpanIframeReplaceParams = + SpanIframeReplaceParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + @JvmSynthetic internal fun _body(): Body = body override fun _headers(): Headers = additionalHeaders override fun _queryParams(): QueryParams = additionalQueryParams - @NoAutoDetect class Body - @JsonCreator private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("project_id") - @ExcludeMissing - private val projectId: JsonField = JsonMissing.of(), - @JsonProperty("url") @ExcludeMissing private val url: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("post_message") - @ExcludeMissing - private val postMessage: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + private val name: JsonField, + private val projectId: JsonField, + private val url: JsonField, + private val description: JsonField, + private val postMessage: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("url") @ExcludeMissing url: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("post_message") + @ExcludeMissing + postMessage: JsonField = JsonMissing.of(), + ) : this(name, projectId, url, description, postMessage, mutableMapOf()) + /** * Name of the span iframe * @@ -224,24 +470,15 @@ private constructor( @ExcludeMissing fun _postMessage(): JsonField = postMessage + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } - - name() - projectId() - url() - description() - postMessage() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -400,10 +637,25 @@ private constructor( checkRequired("url", url), description, postMessage, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + name() + projectId() + url() + description() + postMessage() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -422,251 +674,6 @@ private constructor( "Body{name=$name, projectId=$projectId, url=$url, description=$description, postMessage=$postMessage, additionalProperties=$additionalProperties}" } - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [SpanIframeReplaceParams]. - * - * The following fields are required: - * ```java - * .name() - * .projectId() - * .url() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [SpanIframeReplaceParams]. */ - @NoAutoDetect - class Builder internal constructor() { - - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - - @JvmSynthetic - internal fun from(spanIframeReplaceParams: SpanIframeReplaceParams) = apply { - body = spanIframeReplaceParams.body.toBuilder() - additionalHeaders = spanIframeReplaceParams.additionalHeaders.toBuilder() - additionalQueryParams = spanIframeReplaceParams.additionalQueryParams.toBuilder() - } - - /** Name of the span iframe */ - fun name(name: String) = apply { body.name(name) } - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun name(name: JsonField) = apply { body.name(name) } - - /** Unique identifier for the project that the span iframe belongs under */ - fun projectId(projectId: String) = apply { body.projectId(projectId) } - - /** - * Sets [Builder.projectId] to an arbitrary JSON value. - * - * You should usually call [Builder.projectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun projectId(projectId: JsonField) = apply { body.projectId(projectId) } - - /** URL to embed the project viewer in an iframe */ - fun url(url: String) = apply { body.url(url) } - - /** - * Sets [Builder.url] to an arbitrary JSON value. - * - * You should usually call [Builder.url] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun url(url: JsonField) = apply { body.url(url) } - - /** Textual description of the span iframe */ - fun description(description: String?) = apply { body.description(description) } - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) - - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun description(description: JsonField) = apply { body.description(description) } - - /** - * Whether to post messages to the iframe containing the span's data. This is useful when - * you want to render more data than fits in the URL. - */ - fun postMessage(postMessage: Boolean?) = apply { body.postMessage(postMessage) } - - /** - * Alias for [Builder.postMessage]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun postMessage(postMessage: Boolean) = postMessage(postMessage as Boolean?) - - /** Alias for calling [Builder.postMessage] with `postMessage.orElse(null)`. */ - fun postMessage(postMessage: Optional) = postMessage(postMessage.getOrNull()) - - /** - * Sets [Builder.postMessage] to an arbitrary JSON value. - * - * You should usually call [Builder.postMessage] with a well-typed [Boolean] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun postMessage(postMessage: JsonField) = apply { body.postMessage(postMessage) } - - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) - } - - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) - } - - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) - } - - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } - - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } - - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } - - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } - - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } - - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(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 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) - } - - /** - * Returns an immutable instance of [SpanIframeReplaceParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * .projectId() - * .url() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): SpanIframeReplaceParams = - SpanIframeReplaceParams( - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeRetrieveParams.kt index 17eb5190..63c737bb 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeRetrieveParams.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers @@ -24,16 +23,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _pathParam(index: Int): String = - when (index) { - 0 -> spanIframeId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - fun toBuilder() = Builder().from(this) companion object { @@ -50,7 +39,6 @@ private constructor( } /** A builder for [SpanIframeRetrieveParams]. */ - @NoAutoDetect class Builder internal constructor() { private var spanIframeId: String? = null @@ -185,6 +173,16 @@ private constructor( ) } + fun _pathParam(index: Int): String = + when (index) { + 0 -> spanIframeId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParams.kt index 2db7b7cc..865a00b7 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParams.kt @@ -6,18 +6,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -105,267 +103,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - fun _pathParam(index: Int): String = - when (index) { - 0 -> spanIframeId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("post_message") - @ExcludeMissing - private val postMessage: JsonField = JsonMissing.of(), - @JsonProperty("url") @ExcludeMissing private val url: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { - - /** - * Textual description of the span iframe - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) - - /** - * Name of the span iframe - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) - - /** - * Whether to post messages to the iframe containing the span's data. This is useful when - * you want to render more data than fits in the URL. - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun postMessage(): Optional = - Optional.ofNullable(postMessage.getNullable("post_message")) - - /** - * URL to embed the project viewer in an iframe - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun url(): Optional = Optional.ofNullable(url.getNullable("url")) - - /** - * Returns the raw JSON value of [description]. - * - * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("description") - @ExcludeMissing - fun _description(): JsonField = description - - /** - * Returns the raw JSON value of [name]. - * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - - /** - * Returns the raw JSON value of [postMessage]. - * - * Unlike [postMessage], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("post_message") - @ExcludeMissing - fun _postMessage(): JsonField = postMessage - - /** - * Returns the raw JSON value of [url]. - * - * Unlike [url], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("url") @ExcludeMissing fun _url(): JsonField = url - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } - - description() - name() - postMessage() - url() - validated = true - } - - fun toBuilder() = Builder().from(this) - - companion object { - - /** Returns a mutable builder for constructing an instance of [Body]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var description: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var postMessage: JsonField = JsonMissing.of() - private var url: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - description = body.description - name = body.name - postMessage = body.postMessage - url = body.url - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** Textual description of the span iframe */ - fun description(description: String?) = description(JsonField.ofNullable(description)) - - /** Alias for calling [Builder.description] with `description.orElse(null)`. */ - fun description(description: Optional) = description(description.getOrNull()) - - /** - * Sets [Builder.description] to an arbitrary JSON value. - * - * You should usually call [Builder.description] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun description(description: JsonField) = apply { - this.description = description - } - - /** Name of the span iframe */ - fun name(name: String?) = name(JsonField.ofNullable(name)) - - /** Alias for calling [Builder.name] with `name.orElse(null)`. */ - fun name(name: Optional) = name(name.getOrNull()) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } - - /** - * Whether to post messages to the iframe containing the span's data. This is useful - * when you want to render more data than fits in the URL. - */ - fun postMessage(postMessage: Boolean?) = postMessage(JsonField.ofNullable(postMessage)) - - /** - * Alias for [Builder.postMessage]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun postMessage(postMessage: Boolean) = postMessage(postMessage as Boolean?) - - /** Alias for calling [Builder.postMessage] with `postMessage.orElse(null)`. */ - fun postMessage(postMessage: Optional) = postMessage(postMessage.getOrNull()) - - /** - * Sets [Builder.postMessage] to an arbitrary JSON value. - * - * You should usually call [Builder.postMessage] with a well-typed [Boolean] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun postMessage(postMessage: JsonField) = apply { - this.postMessage = postMessage - } - - /** URL to embed the project viewer in an iframe */ - fun url(url: String?) = url(JsonField.ofNullable(url)) - - /** Alias for calling [Builder.url] with `url.orElse(null)`. */ - fun url(url: Optional) = url(url.getOrNull()) - - /** - * Sets [Builder.url] to an arbitrary JSON value. - * - * You should usually call [Builder.url] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun url(url: JsonField) = apply { this.url = url } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - 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) - } - - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Body = - Body(description, name, postMessage, url, additionalProperties.toImmutable()) - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Body && description == other.description && name == other.name && postMessage == other.postMessage && url == other.url && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(description, name, postMessage, url, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Body{description=$description, name=$name, postMessage=$postMessage, url=$url, additionalProperties=$additionalProperties}" - } - fun toBuilder() = Builder().from(this) companion object { @@ -382,7 +119,6 @@ private constructor( } /** A builder for [SpanIframeUpdateParams]. */ - @NoAutoDetect class Builder internal constructor() { private var spanIframeId: String? = null @@ -607,6 +343,276 @@ private constructor( ) } + @JvmSynthetic internal fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> spanIframeId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val description: JsonField, + private val name: JsonField, + private val postMessage: JsonField, + private val url: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("post_message") + @ExcludeMissing + postMessage: JsonField = JsonMissing.of(), + @JsonProperty("url") @ExcludeMissing url: JsonField = JsonMissing.of(), + ) : this(description, name, postMessage, url, mutableMapOf()) + + /** + * Textual description of the span iframe + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun description(): Optional = + Optional.ofNullable(description.getNullable("description")) + + /** + * Name of the span iframe + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + /** + * Whether to post messages to the iframe containing the span's data. This is useful when + * you want to render more data than fits in the URL. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun postMessage(): Optional = + Optional.ofNullable(postMessage.getNullable("post_message")) + + /** + * URL to embed the project viewer in an iframe + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun url(): Optional = Optional.ofNullable(url.getNullable("url")) + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [postMessage]. + * + * Unlike [postMessage], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("post_message") + @ExcludeMissing + fun _postMessage(): JsonField = postMessage + + /** + * Returns the raw JSON value of [url]. + * + * Unlike [url], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("url") @ExcludeMissing fun _url(): JsonField = url + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Body]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var description: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var postMessage: JsonField = JsonMissing.of() + private var url: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + description = body.description + name = body.name + postMessage = body.postMessage + url = body.url + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** Textual description of the span iframe */ + fun description(description: String?) = description(JsonField.ofNullable(description)) + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } + + /** Name of the span iframe */ + fun name(name: String?) = name(JsonField.ofNullable(name)) + + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** + * Whether to post messages to the iframe containing the span's data. This is useful + * when you want to render more data than fits in the URL. + */ + fun postMessage(postMessage: Boolean?) = postMessage(JsonField.ofNullable(postMessage)) + + /** + * Alias for [Builder.postMessage]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun postMessage(postMessage: Boolean) = postMessage(postMessage as Boolean?) + + /** Alias for calling [Builder.postMessage] with `postMessage.orElse(null)`. */ + fun postMessage(postMessage: Optional) = postMessage(postMessage.getOrNull()) + + /** + * Sets [Builder.postMessage] to an arbitrary JSON value. + * + * You should usually call [Builder.postMessage] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun postMessage(postMessage: JsonField) = apply { + this.postMessage = postMessage + } + + /** URL to embed the project viewer in an iframe */ + fun url(url: String?) = url(JsonField.ofNullable(url)) + + /** Alias for calling [Builder.url] with `url.orElse(null)`. */ + fun url(url: Optional) = url(url.getOrNull()) + + /** + * Sets [Builder.url] to an arbitrary JSON value. + * + * You should usually call [Builder.url] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun url(url: JsonField) = apply { this.url = url } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Body = + Body(description, name, postMessage, url, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + description() + name() + postMessage() + url() + validated = true + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && description == other.description && name == other.name && postMessage == other.postMessage && url == other.url && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(description, name, postMessage, url, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{description=$description, name=$name, postMessage=$postMessage, url=$url, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SummarizeDatasetResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SummarizeDatasetResponse.kt index 78210f20..940aa2ad 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SummarizeDatasetResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SummarizeDatasetResponse.kt @@ -6,42 +6,47 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Summary of a dataset */ -@NoAutoDetect class SummarizeDatasetResponse -@JsonCreator private constructor( - @JsonProperty("dataset_name") - @ExcludeMissing - private val datasetName: JsonField = JsonMissing.of(), - @JsonProperty("dataset_url") - @ExcludeMissing - private val datasetUrl: JsonField = JsonMissing.of(), - @JsonProperty("project_name") - @ExcludeMissing - private val projectName: JsonField = JsonMissing.of(), - @JsonProperty("project_url") - @ExcludeMissing - private val projectUrl: JsonField = JsonMissing.of(), - @JsonProperty("data_summary") - @ExcludeMissing - private val dataSummary: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val datasetName: JsonField, + private val datasetUrl: JsonField, + private val projectName: JsonField, + private val projectUrl: JsonField, + private val dataSummary: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("dataset_name") + @ExcludeMissing + datasetName: JsonField = JsonMissing.of(), + @JsonProperty("dataset_url") + @ExcludeMissing + datasetUrl: JsonField = JsonMissing.of(), + @JsonProperty("project_name") + @ExcludeMissing + projectName: JsonField = JsonMissing.of(), + @JsonProperty("project_url") + @ExcludeMissing + projectUrl: JsonField = JsonMissing.of(), + @JsonProperty("data_summary") + @ExcludeMissing + dataSummary: JsonField = JsonMissing.of(), + ) : this(datasetName, datasetUrl, projectName, projectUrl, dataSummary, mutableMapOf()) + /** * Name of the dataset * @@ -124,24 +129,15 @@ private constructor( @ExcludeMissing fun _dataSummary(): JsonField = dataSummary + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): SummarizeDatasetResponse = apply { - if (validated) { - return@apply - } - - datasetName() - datasetUrl() - projectName() - projectUrl() - dataSummary().ifPresent { it.validate() } - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -287,10 +283,25 @@ private constructor( checkRequired("projectName", projectName), checkRequired("projectUrl", projectUrl), dataSummary, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): SummarizeDatasetResponse = apply { + if (validated) { + return@apply + } + + datasetName() + datasetUrl() + projectName() + projectUrl() + dataSummary().ifPresent { it.validate() } + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SummarizeExperimentResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SummarizeExperimentResponse.kt index 1c8a412a..1158c9d9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SummarizeExperimentResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SummarizeExperimentResponse.kt @@ -6,48 +6,60 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Summary of an experiment */ -@NoAutoDetect class SummarizeExperimentResponse -@JsonCreator private constructor( - @JsonProperty("experiment_name") - @ExcludeMissing - private val experimentName: JsonField = JsonMissing.of(), - @JsonProperty("experiment_url") - @ExcludeMissing - private val experimentUrl: JsonField = JsonMissing.of(), - @JsonProperty("project_name") - @ExcludeMissing - private val projectName: JsonField = JsonMissing.of(), - @JsonProperty("project_url") - @ExcludeMissing - private val projectUrl: JsonField = JsonMissing.of(), - @JsonProperty("comparison_experiment_name") - @ExcludeMissing - private val comparisonExperimentName: JsonField = JsonMissing.of(), - @JsonProperty("metrics") - @ExcludeMissing - private val metrics: JsonField = JsonMissing.of(), - @JsonProperty("scores") - @ExcludeMissing - private val scores: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val experimentName: JsonField, + private val experimentUrl: JsonField, + private val projectName: JsonField, + private val projectUrl: JsonField, + private val comparisonExperimentName: JsonField, + private val metrics: JsonField, + private val scores: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("experiment_name") + @ExcludeMissing + experimentName: JsonField = JsonMissing.of(), + @JsonProperty("experiment_url") + @ExcludeMissing + experimentUrl: JsonField = JsonMissing.of(), + @JsonProperty("project_name") + @ExcludeMissing + projectName: JsonField = JsonMissing.of(), + @JsonProperty("project_url") + @ExcludeMissing + projectUrl: JsonField = JsonMissing.of(), + @JsonProperty("comparison_experiment_name") + @ExcludeMissing + comparisonExperimentName: JsonField = JsonMissing.of(), + @JsonProperty("metrics") @ExcludeMissing metrics: JsonField = JsonMissing.of(), + @JsonProperty("scores") @ExcludeMissing scores: JsonField = JsonMissing.of(), + ) : this( + experimentName, + experimentUrl, + projectName, + projectUrl, + comparisonExperimentName, + metrics, + scores, + mutableMapOf(), + ) + /** * Name of the experiment * @@ -163,26 +175,15 @@ private constructor( */ @JsonProperty("scores") @ExcludeMissing fun _scores(): JsonField = scores + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): SummarizeExperimentResponse = apply { - if (validated) { - return@apply - } - - experimentName() - experimentUrl() - projectName() - projectUrl() - comparisonExperimentName() - metrics().ifPresent { it.validate() } - scores().ifPresent { it.validate() } - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -371,32 +372,42 @@ private constructor( comparisonExperimentName, metrics, scores, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): SummarizeExperimentResponse = apply { + if (validated) { + return@apply + } + + experimentName() + experimentUrl() + projectName() + projectUrl() + comparisonExperimentName() + metrics().ifPresent { it.validate() } + scores().ifPresent { it.validate() } + validated = true + } + /** Summary of the experiment's metrics */ - @NoAutoDetect class Metrics - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Metrics = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -440,7 +451,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metrics = Metrics(additionalProperties.toImmutable()) + fun build(): Metrics = Metrics(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metrics = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { @@ -461,27 +482,20 @@ private constructor( } /** Summary of the experiment's scores */ - @NoAutoDetect class Scores - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Scores = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -525,7 +539,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Scores = Scores(additionalProperties.toImmutable()) + fun build(): Scores = Scores(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Scores = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/TopLevelHelloWorldParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/TopLevelHelloWorldParams.kt index e6ef1cd1..07da14b6 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/TopLevelHelloWorldParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/TopLevelHelloWorldParams.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams @@ -19,10 +18,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - fun toBuilder() = Builder().from(this) companion object { @@ -34,7 +29,6 @@ private constructor( } /** A builder for [TopLevelHelloWorldParams]. */ - @NoAutoDetect class Builder internal constructor() { private var additionalHeaders: Headers.Builder = Headers.builder() @@ -153,6 +147,10 @@ private constructor( TopLevelHelloWorldParams(additionalHeaders.build(), additionalQueryParams.build()) } + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/User.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/User.kt index ac80f854..d0bbfc7b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/User.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/User.kt @@ -6,41 +6,43 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class User -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("avatar_url") - @ExcludeMissing - private val avatarUrl: JsonField = JsonMissing.of(), - @JsonProperty("created") - @ExcludeMissing - private val created: JsonField = JsonMissing.of(), - @JsonProperty("email") @ExcludeMissing private val email: JsonField = JsonMissing.of(), - @JsonProperty("family_name") - @ExcludeMissing - private val familyName: JsonField = JsonMissing.of(), - @JsonProperty("given_name") - @ExcludeMissing - private val givenName: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val avatarUrl: JsonField, + private val created: JsonField, + private val email: JsonField, + private val familyName: JsonField, + private val givenName: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("avatar_url") @ExcludeMissing avatarUrl: JsonField = JsonMissing.of(), + @JsonProperty("created") + @ExcludeMissing + created: JsonField = JsonMissing.of(), + @JsonProperty("email") @ExcludeMissing email: JsonField = JsonMissing.of(), + @JsonProperty("family_name") + @ExcludeMissing + familyName: JsonField = JsonMissing.of(), + @JsonProperty("given_name") @ExcludeMissing givenName: JsonField = JsonMissing.of(), + ) : this(id, avatarUrl, created, email, familyName, givenName, mutableMapOf()) + /** * Unique identifier for the user * @@ -131,25 +133,15 @@ private constructor( */ @JsonProperty("given_name") @ExcludeMissing fun _givenName(): JsonField = givenName + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): User = apply { - if (validated) { - return@apply - } - - id() - avatarUrl() - created() - email() - familyName() - givenName() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -312,10 +304,26 @@ private constructor( email, familyName, givenName, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): User = apply { + if (validated) { + return@apply + } + + id() + avatarUrl() + created() + email() + familyName() + givenName() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt index c1feb5eb..8afb6f9d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.blocking.UserService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -81,23 +79,30 @@ private constructor( UserListPage(usersService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -155,7 +160,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt index 23c28a26..b5424cfd 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.async.UserServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -83,23 +81,30 @@ private constructor( UserListPageAsync(usersService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -157,7 +162,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListParams.kt index 55618ca7..46e6805d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListParams.kt @@ -5,7 +5,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.BaseDeserializer import com.braintrustdata.api.core.BaseSerializer import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers @@ -92,63 +91,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = - QueryParams.builder() - .apply { - email?.accept( - object : Email.Visitor { - override fun visitString(string: String) { - put("email", string) - } - - override fun visitStrings(strings: List) { - put("email", strings.joinToString(",")) - } - } - ) - endingBefore?.let { put("ending_before", it) } - familyName?.accept( - object : FamilyName.Visitor { - override fun visitString(string: String) { - put("family_name", string) - } - - override fun visitStrings(strings: List) { - put("family_name", strings.joinToString(",")) - } - } - ) - givenName?.accept( - object : GivenName.Visitor { - override fun visitString(string: String) { - put("given_name", string) - } - - override fun visitStrings(strings: List) { - put("given_name", strings.joinToString(",")) - } - } - ) - ids?.accept( - object : Ids.Visitor { - override fun visitString(string: String) { - put("ids", string) - } - - override fun visitStrings(strings: List) { - put("ids", strings.joinToString(",")) - } - } - ) - limit?.let { put("limit", it.toString()) } - orgName?.let { put("org_name", it) } - startingAfter?.let { put("starting_after", it) } - putAll(additionalQueryParams) - } - .build() - fun toBuilder() = Builder().from(this) companion object { @@ -160,7 +102,6 @@ private constructor( } /** A builder for [UserListParams]. */ - @NoAutoDetect class Builder internal constructor() { private var email: Email? = null @@ -410,6 +351,63 @@ private constructor( ) } + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + email?.accept( + object : Email.Visitor { + override fun visitString(string: String) { + put("email", string) + } + + override fun visitStrings(strings: List) { + put("email", strings.joinToString(",")) + } + } + ) + endingBefore?.let { put("ending_before", it) } + familyName?.accept( + object : FamilyName.Visitor { + override fun visitString(string: String) { + put("family_name", string) + } + + override fun visitStrings(strings: List) { + put("family_name", strings.joinToString(",")) + } + } + ) + givenName?.accept( + object : GivenName.Visitor { + override fun visitString(string: String) { + put("given_name", string) + } + + override fun visitStrings(strings: List) { + put("given_name", strings.joinToString(",")) + } + } + ) + ids?.accept( + object : Ids.Visitor { + override fun visitString(string: String) { + put("ids", string) + } + + override fun visitStrings(strings: List) { + put("ids", strings.joinToString(",")) + } + } + ) + limit?.let { put("limit", it.toString()) } + orgName?.let { put("org_name", it) } + startingAfter?.let { put("starting_after", it) } + putAll(additionalQueryParams) + } + .build() + /** * Email of the user to search for. You may pass the param multiple times to filter for more * than one email diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserRetrieveParams.kt index 2f44ce84..3a97c821 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserRetrieveParams.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers @@ -24,16 +23,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _pathParam(index: Int): String = - when (index) { - 0 -> userId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - fun toBuilder() = Builder().from(this) companion object { @@ -50,7 +39,6 @@ private constructor( } /** A builder for [UserRetrieveParams]. */ - @NoAutoDetect class Builder internal constructor() { private var userId: String? = null @@ -185,6 +173,16 @@ private constructor( ) } + fun _pathParam(index: Int): String = + when (index) { + 0 -> userId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/View.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/View.kt index f7439666..d6f9dc50 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/View.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/View.kt @@ -7,53 +7,65 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkRequired -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class View -@JsonCreator private constructor( - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing private val name: JsonField = JsonMissing.of(), - @JsonProperty("object_id") - @ExcludeMissing - private val objectId: JsonField = JsonMissing.of(), - @JsonProperty("object_type") - @ExcludeMissing - private val objectType: JsonField = JsonMissing.of(), - @JsonProperty("view_type") - @ExcludeMissing - private val viewType: JsonField = JsonMissing.of(), - @JsonProperty("created") - @ExcludeMissing - private val created: JsonField = JsonMissing.of(), - @JsonProperty("deleted_at") - @ExcludeMissing - private val deletedAt: JsonField = JsonMissing.of(), - @JsonProperty("options") - @ExcludeMissing - private val options: JsonField = JsonMissing.of(), - @JsonProperty("user_id") - @ExcludeMissing - private val userId: JsonField = JsonMissing.of(), - @JsonProperty("view_data") - @ExcludeMissing - private val viewData: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val id: JsonField, + private val name: JsonField, + private val objectId: JsonField, + private val objectType: JsonField, + private val viewType: JsonField, + private val created: JsonField, + private val deletedAt: JsonField, + private val options: JsonField, + private val userId: JsonField, + private val viewData: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("object_id") @ExcludeMissing objectId: JsonField = JsonMissing.of(), + @JsonProperty("object_type") + @ExcludeMissing + objectType: JsonField = JsonMissing.of(), + @JsonProperty("view_type") @ExcludeMissing viewType: JsonField = JsonMissing.of(), + @JsonProperty("created") + @ExcludeMissing + created: JsonField = JsonMissing.of(), + @JsonProperty("deleted_at") + @ExcludeMissing + deletedAt: JsonField = JsonMissing.of(), + @JsonProperty("options") @ExcludeMissing options: JsonField = JsonMissing.of(), + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), + @JsonProperty("view_data") @ExcludeMissing viewData: JsonField = JsonMissing.of(), + ) : this( + id, + name, + objectId, + objectType, + viewType, + created, + deletedAt, + options, + userId, + viewData, + mutableMapOf(), + ) + /** * Unique identifier for the view * @@ -209,29 +221,15 @@ private constructor( */ @JsonProperty("view_data") @ExcludeMissing fun _viewData(): JsonField = viewData + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): View = apply { - if (validated) { - return@apply - } - - id() - name() - objectId() - objectType() - viewType() - created() - deletedAt() - options().ifPresent { it.validate() } - userId() - viewData().ifPresent { it.validate() } - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -465,10 +463,30 @@ private constructor( options, userId, viewData, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): View = apply { + if (validated) { + return@apply + } + + id() + name() + objectId() + objectType() + viewType() + created() + deletedAt() + options().ifPresent { it.validate() } + userId() + viewData().ifPresent { it.validate() } + validated = true + } + /** Type of table that the view corresponds to. */ class ViewType @JsonCreator private constructor(private val value: JsonField) : Enum { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewCreateParams.kt index da386fa5..53dae27a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewCreateParams.kt @@ -7,19 +7,17 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -161,422 +159,267 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams + fun toBuilder() = Builder().from(this) - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("object_id") - @ExcludeMissing - private val objectId: JsonField = JsonMissing.of(), - @JsonProperty("object_type") - @ExcludeMissing - private val objectType: JsonField = JsonMissing.of(), - @JsonProperty("view_type") - @ExcludeMissing - private val viewType: JsonField = JsonMissing.of(), - @JsonProperty("deleted_at") - @ExcludeMissing - private val deletedAt: JsonField = JsonMissing.of(), - @JsonProperty("options") - @ExcludeMissing - private val options: JsonField = JsonMissing.of(), - @JsonProperty("user_id") - @ExcludeMissing - private val userId: JsonField = JsonMissing.of(), - @JsonProperty("view_data") - @ExcludeMissing - private val viewData: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + companion object { /** - * Name of the view + * Returns a mutable builder for constructing an instance of [ViewCreateParams]. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + * The following fields are required: + * ```java + * .name() + * .objectId() + * .objectType() + * .viewType() + * ``` */ - fun name(): String = name.getRequired("name") + @JvmStatic fun builder() = Builder() + } - /** - * The id of the object the view applies to - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun objectId(): String = objectId.getRequired("object_id") + /** A builder for [ViewCreateParams]. */ + class Builder internal constructor() { - /** - * The object type that the ACL applies to - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun objectType(): AclObjectType = objectType.getRequired("object_type") + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - /** - * Type of table that the view corresponds to. - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun viewType(): Optional = Optional.ofNullable(viewType.getNullable("view_type")) + @JvmSynthetic + internal fun from(viewCreateParams: ViewCreateParams) = apply { + body = viewCreateParams.body.toBuilder() + additionalHeaders = viewCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = viewCreateParams.additionalQueryParams.toBuilder() + } - /** - * Date of role deletion, or null if the role is still active - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun deletedAt(): Optional = - Optional.ofNullable(deletedAt.getNullable("deleted_at")) + /** Name of the view */ + fun name(name: String) = apply { body.name(name) } /** - * Options for the view in the app + * Sets [Builder.name] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun options(): Optional = Optional.ofNullable(options.getNullable("options")) + fun name(name: JsonField) = apply { body.name(name) } - /** - * Identifies the user who created the view - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) + /** The id of the object the view applies to */ + fun objectId(objectId: String) = apply { body.objectId(objectId) } /** - * The view definition + * Sets [Builder.objectId] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.objectId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun viewData(): Optional = Optional.ofNullable(viewData.getNullable("view_data")) + fun objectId(objectId: JsonField) = apply { body.objectId(objectId) } - /** - * Returns the raw JSON value of [name]. - * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + /** The object type that the ACL applies to */ + fun objectType(objectType: AclObjectType) = apply { body.objectType(objectType) } /** - * Returns the raw JSON value of [objectId]. + * Sets [Builder.objectType] to an arbitrary JSON value. * - * Unlike [objectId], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.objectType] with a well-typed [AclObjectType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("object_id") @ExcludeMissing fun _objectId(): JsonField = objectId + fun objectType(objectType: JsonField) = apply { body.objectType(objectType) } - /** - * Returns the raw JSON value of [objectType]. - * - * Unlike [objectType], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("object_type") - @ExcludeMissing - fun _objectType(): JsonField = objectType + /** Type of table that the view corresponds to. */ + fun viewType(viewType: ViewType?) = apply { body.viewType(viewType) } + + /** Alias for calling [Builder.viewType] with `viewType.orElse(null)`. */ + fun viewType(viewType: Optional) = viewType(viewType.getOrNull()) /** - * Returns the raw JSON value of [viewType]. + * Sets [Builder.viewType] to an arbitrary JSON value. * - * Unlike [viewType], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.viewType] with a well-typed [ViewType] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("view_type") @ExcludeMissing fun _viewType(): JsonField = viewType + fun viewType(viewType: JsonField) = apply { body.viewType(viewType) } + + /** Date of role deletion, or null if the role is still active */ + fun deletedAt(deletedAt: OffsetDateTime?) = apply { body.deletedAt(deletedAt) } + + /** Alias for calling [Builder.deletedAt] with `deletedAt.orElse(null)`. */ + fun deletedAt(deletedAt: Optional) = deletedAt(deletedAt.getOrNull()) /** - * Returns the raw JSON value of [deletedAt]. + * Sets [Builder.deletedAt] to an arbitrary JSON value. * - * Unlike [deletedAt], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.deletedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("deleted_at") - @ExcludeMissing - fun _deletedAt(): JsonField = deletedAt + fun deletedAt(deletedAt: JsonField) = apply { body.deletedAt(deletedAt) } + + /** Options for the view in the app */ + fun options(options: ViewOptions?) = apply { body.options(options) } + + /** Alias for calling [Builder.options] with `options.orElse(null)`. */ + fun options(options: Optional) = options(options.getOrNull()) /** - * Returns the raw JSON value of [options]. + * Sets [Builder.options] to an arbitrary JSON value. * - * Unlike [options], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.options] with a well-typed [ViewOptions] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("options") @ExcludeMissing fun _options(): JsonField = options + fun options(options: JsonField) = apply { body.options(options) } + + /** Identifies the user who created the view */ + fun userId(userId: String?) = apply { body.userId(userId) } + + /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ + fun userId(userId: Optional) = userId(userId.getOrNull()) /** - * Returns the raw JSON value of [userId]. + * Sets [Builder.userId] to an arbitrary JSON value. * - * Unlike [userId], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.userId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + fun userId(userId: JsonField) = apply { body.userId(userId) } + + /** The view definition */ + fun viewData(viewData: ViewData?) = apply { body.viewData(viewData) } + + /** Alias for calling [Builder.viewData] with `viewData.orElse(null)`. */ + fun viewData(viewData: Optional) = viewData(viewData.getOrNull()) /** - * Returns the raw JSON value of [viewData]. + * Sets [Builder.viewData] to an arbitrary JSON value. * - * Unlike [viewData], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.viewData] with a well-typed [ViewData] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("view_data") @ExcludeMissing fun _viewData(): JsonField = viewData + fun viewData(viewData: JsonField) = apply { body.viewData(viewData) } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } - private var validated: Boolean = false + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } - fun validate(): Body = apply { - if (validated) { - return@apply + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) } - name() - objectId() - objectType() - viewType() - deletedAt() - options().ifPresent { it.validate() } - userId() - viewData().ifPresent { it.validate() } - validated = true + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) } - fun toBuilder() = Builder().from(this) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - companion object { + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .name() - * .objectId() - * .objectType() - * .viewType() - * ``` - */ - @JvmStatic fun builder() = Builder() + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - /** A builder for [Body]. */ - class Builder internal constructor() { + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - private var name: JsonField? = null - private var objectId: JsonField? = null - private var objectType: JsonField? = null - private var viewType: JsonField? = null - private var deletedAt: JsonField = JsonMissing.of() - private var options: JsonField = JsonMissing.of() - private var userId: JsonField = JsonMissing.of() - private var viewData: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - name = body.name - objectId = body.objectId - objectType = body.objectType - viewType = body.viewType - deletedAt = body.deletedAt - options = body.options - userId = body.userId - viewData = body.viewData - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** Name of the view */ - fun name(name: String) = name(JsonField.of(name)) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } - - /** The id of the object the view applies to */ - fun objectId(objectId: String) = objectId(JsonField.of(objectId)) - - /** - * Sets [Builder.objectId] to an arbitrary JSON value. - * - * You should usually call [Builder.objectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun objectId(objectId: JsonField) = apply { this.objectId = objectId } - - /** The object type that the ACL applies to */ - fun objectType(objectType: AclObjectType) = objectType(JsonField.of(objectType)) - - /** - * Sets [Builder.objectType] to an arbitrary JSON value. - * - * You should usually call [Builder.objectType] with a well-typed [AclObjectType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun objectType(objectType: JsonField) = apply { - this.objectType = objectType - } - - /** Type of table that the view corresponds to. */ - fun viewType(viewType: ViewType?) = viewType(JsonField.ofNullable(viewType)) - - /** Alias for calling [Builder.viewType] with `viewType.orElse(null)`. */ - fun viewType(viewType: Optional) = viewType(viewType.getOrNull()) - - /** - * Sets [Builder.viewType] to an arbitrary JSON value. - * - * You should usually call [Builder.viewType] with a well-typed [ViewType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun viewType(viewType: JsonField) = apply { this.viewType = viewType } - - /** Date of role deletion, or null if the role is still active */ - fun deletedAt(deletedAt: OffsetDateTime?) = deletedAt(JsonField.ofNullable(deletedAt)) - - /** Alias for calling [Builder.deletedAt] with `deletedAt.orElse(null)`. */ - fun deletedAt(deletedAt: Optional) = deletedAt(deletedAt.getOrNull()) - - /** - * Sets [Builder.deletedAt] to an arbitrary JSON value. - * - * You should usually call [Builder.deletedAt] with a well-typed [OffsetDateTime] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun deletedAt(deletedAt: JsonField) = apply { - this.deletedAt = deletedAt - } - - /** Options for the view in the app */ - fun options(options: ViewOptions?) = options(JsonField.ofNullable(options)) - - /** Alias for calling [Builder.options] with `options.orElse(null)`. */ - fun options(options: Optional) = options(options.getOrNull()) - - /** - * Sets [Builder.options] to an arbitrary JSON value. - * - * You should usually call [Builder.options] with a well-typed [ViewOptions] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun options(options: JsonField) = apply { this.options = options } + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** Identifies the user who created the view */ - fun userId(userId: String?) = userId(JsonField.ofNullable(userId)) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ - fun userId(userId: Optional) = userId(userId.getOrNull()) + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - /** - * Sets [Builder.userId] to an arbitrary JSON value. - * - * You should usually call [Builder.userId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun userId(userId: JsonField) = apply { this.userId = userId } + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** The view definition */ - fun viewData(viewData: ViewData?) = viewData(JsonField.ofNullable(viewData)) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** Alias for calling [Builder.viewData] with `viewData.orElse(null)`. */ - fun viewData(viewData: Optional) = viewData(viewData.getOrNull()) + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Sets [Builder.viewData] to an arbitrary JSON value. - * - * You should usually call [Builder.viewData] with a well-typed [ViewData] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun viewData(viewData: JsonField) = apply { this.viewData = viewData } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * .objectId() - * .objectType() - * .viewType() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("name", name), - checkRequired("objectId", objectId), - checkRequired("objectType", objectType), - checkRequired("viewType", viewType), - deletedAt, - options, - userId, - viewData, - additionalProperties.toImmutable(), - ) + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - return /* spotless:off */ other is Body && name == other.name && objectId == other.objectId && objectType == other.objectType && viewType == other.viewType && deletedAt == other.deletedAt && options == other.options && userId == other.userId && viewData == other.viewData && additionalProperties == other.additionalProperties /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, objectId, objectType, viewType, deletedAt, options, userId, viewData, additionalProperties) } - /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } - override fun hashCode(): Int = hashCode + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - override fun toString() = - "Body{name=$name, objectId=$objectId, objectType=$objectType, viewType=$viewType, deletedAt=$deletedAt, options=$options, userId=$userId, viewData=$viewData, additionalProperties=$additionalProperties}" - } + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - fun toBuilder() = Builder().from(this) + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - companion object { + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } /** - * Returns a mutable builder for constructing an instance of [ViewCreateParams]. + * Returns an immutable instance of [ViewCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java @@ -585,267 +428,442 @@ private constructor( * .objectType() * .viewType() * ``` + * + * @throws IllegalStateException if any required field is unset. */ - @JvmStatic fun builder() = Builder() + fun build(): ViewCreateParams = + ViewCreateParams(body.build(), additionalHeaders.build(), additionalQueryParams.build()) } - /** A builder for [ViewCreateParams]. */ - @NoAutoDetect - class Builder internal constructor() { + @JvmSynthetic internal fun _body(): Body = body - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun from(viewCreateParams: ViewCreateParams) = apply { - body = viewCreateParams.body.toBuilder() - additionalHeaders = viewCreateParams.additionalHeaders.toBuilder() - additionalQueryParams = viewCreateParams.additionalQueryParams.toBuilder() - } + override fun _queryParams(): QueryParams = additionalQueryParams - /** Name of the view */ - fun name(name: String) = apply { body.name(name) } + class Body + private constructor( + private val name: JsonField, + private val objectId: JsonField, + private val objectType: JsonField, + private val viewType: JsonField, + private val deletedAt: JsonField, + private val options: JsonField, + private val userId: JsonField, + private val viewData: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("object_id") + @ExcludeMissing + objectId: JsonField = JsonMissing.of(), + @JsonProperty("object_type") + @ExcludeMissing + objectType: JsonField = JsonMissing.of(), + @JsonProperty("view_type") + @ExcludeMissing + viewType: JsonField = JsonMissing.of(), + @JsonProperty("deleted_at") + @ExcludeMissing + deletedAt: JsonField = JsonMissing.of(), + @JsonProperty("options") + @ExcludeMissing + options: JsonField = JsonMissing.of(), + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), + @JsonProperty("view_data") + @ExcludeMissing + viewData: JsonField = JsonMissing.of(), + ) : this( + name, + objectId, + objectType, + viewType, + deletedAt, + options, + userId, + viewData, + mutableMapOf(), + ) /** - * Sets [Builder.name] to an arbitrary JSON value. + * Name of the view * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun name(name: JsonField) = apply { body.name(name) } - - /** The id of the object the view applies to */ - fun objectId(objectId: String) = apply { body.objectId(objectId) } + fun name(): String = name.getRequired("name") /** - * Sets [Builder.objectId] to an arbitrary JSON value. + * The id of the object the view applies to * - * You should usually call [Builder.objectId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun objectId(objectId: JsonField) = apply { body.objectId(objectId) } - - /** The object type that the ACL applies to */ - fun objectType(objectType: AclObjectType) = apply { body.objectType(objectType) } + fun objectId(): String = objectId.getRequired("object_id") /** - * Sets [Builder.objectType] to an arbitrary JSON value. + * The object type that the ACL applies to * - * You should usually call [Builder.objectType] with a well-typed [AclObjectType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun objectType(objectType: JsonField) = apply { body.objectType(objectType) } - - /** Type of table that the view corresponds to. */ - fun viewType(viewType: ViewType?) = apply { body.viewType(viewType) } - - /** Alias for calling [Builder.viewType] with `viewType.orElse(null)`. */ - fun viewType(viewType: Optional) = viewType(viewType.getOrNull()) + fun objectType(): AclObjectType = objectType.getRequired("object_type") /** - * Sets [Builder.viewType] to an arbitrary JSON value. + * Type of table that the view corresponds to. * - * You should usually call [Builder.viewType] with a well-typed [ViewType] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun viewType(viewType: JsonField) = apply { body.viewType(viewType) } + fun viewType(): Optional = Optional.ofNullable(viewType.getNullable("view_type")) - /** Date of role deletion, or null if the role is still active */ - fun deletedAt(deletedAt: OffsetDateTime?) = apply { body.deletedAt(deletedAt) } + /** + * Date of role deletion, or null if the role is still active + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun deletedAt(): Optional = + Optional.ofNullable(deletedAt.getNullable("deleted_at")) - /** Alias for calling [Builder.deletedAt] with `deletedAt.orElse(null)`. */ - fun deletedAt(deletedAt: Optional) = deletedAt(deletedAt.getOrNull()) + /** + * Options for the view in the app + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun options(): Optional = Optional.ofNullable(options.getNullable("options")) /** - * Sets [Builder.deletedAt] to an arbitrary JSON value. + * Identifies the user who created the view * - * You should usually call [Builder.deletedAt] with a well-typed [OffsetDateTime] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun deletedAt(deletedAt: JsonField) = apply { body.deletedAt(deletedAt) } + fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) - /** Options for the view in the app */ - fun options(options: ViewOptions?) = apply { body.options(options) } + /** + * The view definition + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun viewData(): Optional = Optional.ofNullable(viewData.getNullable("view_data")) - /** Alias for calling [Builder.options] with `options.orElse(null)`. */ - fun options(options: Optional) = options(options.getOrNull()) + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name /** - * Sets [Builder.options] to an arbitrary JSON value. + * Returns the raw JSON value of [objectId]. * - * You should usually call [Builder.options] with a well-typed [ViewOptions] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [objectId], this method doesn't throw if the JSON field has an unexpected type. */ - fun options(options: JsonField) = apply { body.options(options) } + @JsonProperty("object_id") @ExcludeMissing fun _objectId(): JsonField = objectId - /** Identifies the user who created the view */ - fun userId(userId: String?) = apply { body.userId(userId) } + /** + * Returns the raw JSON value of [objectType]. + * + * Unlike [objectType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("object_type") + @ExcludeMissing + fun _objectType(): JsonField = objectType - /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ - fun userId(userId: Optional) = userId(userId.getOrNull()) + /** + * Returns the raw JSON value of [viewType]. + * + * Unlike [viewType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("view_type") @ExcludeMissing fun _viewType(): JsonField = viewType /** - * Sets [Builder.userId] to an arbitrary JSON value. + * Returns the raw JSON value of [deletedAt]. * - * You should usually call [Builder.userId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [deletedAt], this method doesn't throw if the JSON field has an unexpected type. */ - fun userId(userId: JsonField) = apply { body.userId(userId) } + @JsonProperty("deleted_at") + @ExcludeMissing + fun _deletedAt(): JsonField = deletedAt - /** The view definition */ - fun viewData(viewData: ViewData?) = apply { body.viewData(viewData) } + /** + * Returns the raw JSON value of [options]. + * + * Unlike [options], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("options") @ExcludeMissing fun _options(): JsonField = options - /** Alias for calling [Builder.viewData] with `viewData.orElse(null)`. */ - fun viewData(viewData: Optional) = viewData(viewData.getOrNull()) + /** + * Returns the raw JSON value of [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId /** - * Sets [Builder.viewData] to an arbitrary JSON value. + * Returns the raw JSON value of [viewData]. * - * You should usually call [Builder.viewData] with a well-typed [ViewData] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [viewData], this method doesn't throw if the JSON field has an unexpected type. */ - fun viewData(viewData: JsonField) = apply { body.viewData(viewData) } + @JsonProperty("view_data") @ExcludeMissing fun _viewData(): JsonField = viewData - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .name() + * .objectId() + * .objectType() + * .viewType() + * ``` + */ + @JvmStatic fun builder() = Builder() } - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var name: JsonField? = null + private var objectId: JsonField? = null + private var objectType: JsonField? = null + private var viewType: JsonField? = null + private var deletedAt: JsonField = JsonMissing.of() + private var options: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var viewData: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + name = body.name + objectId = body.objectId + objectType = body.objectType + viewType = body.viewType + deletedAt = body.deletedAt + options = body.options + userId = body.userId + viewData = body.viewData + additionalProperties = body.additionalProperties.toMutableMap() } - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + /** Name of the view */ + fun name(name: String) = name(JsonField.of(name)) - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** The id of the object the view applies to */ + fun objectId(objectId: String) = objectId(JsonField.of(objectId)) - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * Sets [Builder.objectId] to an arbitrary JSON value. + * + * You should usually call [Builder.objectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun objectId(objectId: JsonField) = apply { this.objectId = objectId } - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } + /** The object type that the ACL applies to */ + fun objectType(objectType: AclObjectType) = objectType(JsonField.of(objectType)) - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } + /** + * Sets [Builder.objectType] to an arbitrary JSON value. + * + * You should usually call [Builder.objectType] with a well-typed [AclObjectType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun objectType(objectType: JsonField) = apply { + this.objectType = objectType + } - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** Type of table that the view corresponds to. */ + fun viewType(viewType: ViewType?) = viewType(JsonField.ofNullable(viewType)) - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** Alias for calling [Builder.viewType] with `viewType.orElse(null)`. */ + fun viewType(viewType: Optional) = viewType(viewType.getOrNull()) - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } + /** + * Sets [Builder.viewType] to an arbitrary JSON value. + * + * You should usually call [Builder.viewType] with a well-typed [ViewType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun viewType(viewType: JsonField) = apply { this.viewType = viewType } - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } + /** Date of role deletion, or null if the role is still active */ + fun deletedAt(deletedAt: OffsetDateTime?) = deletedAt(JsonField.ofNullable(deletedAt)) - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** Alias for calling [Builder.deletedAt] with `deletedAt.orElse(null)`. */ + fun deletedAt(deletedAt: Optional) = deletedAt(deletedAt.getOrNull()) - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** + * Sets [Builder.deletedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.deletedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun deletedAt(deletedAt: JsonField) = apply { + this.deletedAt = deletedAt + } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + /** Options for the view in the app */ + fun options(options: ViewOptions?) = options(JsonField.ofNullable(options)) - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } + /** Alias for calling [Builder.options] with `options.orElse(null)`. */ + fun options(options: Optional) = options(options.getOrNull()) - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + /** + * Sets [Builder.options] to an arbitrary JSON value. + * + * You should usually call [Builder.options] with a well-typed [ViewOptions] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun options(options: JsonField) = apply { this.options = options } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + /** Identifies the user who created the view */ + fun userId(userId: String?) = userId(JsonField.ofNullable(userId)) - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } + /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ + fun userId(userId: Optional) = userId(userId.getOrNull()) - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) - } + /** + * Sets [Builder.userId] to an arbitrary JSON value. + * + * You should usually call [Builder.userId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun userId(userId: JsonField) = apply { this.userId = userId } - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } + /** The view definition */ + fun viewData(viewData: ViewData?) = viewData(JsonField.ofNullable(viewData)) - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + /** Alias for calling [Builder.viewData] with `viewData.orElse(null)`. */ + fun viewData(viewData: Optional) = viewData(viewData.getOrNull()) + + /** + * Sets [Builder.viewData] to an arbitrary JSON value. + * + * You should usually call [Builder.viewData] with a well-typed [ViewData] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun viewData(viewData: JsonField) = apply { this.viewData = viewData } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) } - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * .objectId() + * .objectType() + * .viewType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("name", name), + checkRequired("objectId", objectId), + checkRequired("objectType", objectType), + checkRequired("viewType", viewType), + deletedAt, + options, + userId, + viewData, + additionalProperties.toMutableMap(), + ) } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply } - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + name() + objectId() + objectType() + viewType() + deletedAt() + options().ifPresent { it.validate() } + userId() + viewData().ifPresent { it.validate() } + validated = true + } - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && name == other.name && objectId == other.objectId && objectType == other.objectType && viewType == other.viewType && deletedAt == other.deletedAt && options == other.options && userId == other.userId && viewData == other.viewData && additionalProperties == other.additionalProperties /* spotless:on */ } - /** - * Returns an immutable instance of [ViewCreateParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * .objectId() - * .objectType() - * .viewType() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ViewCreateParams = - ViewCreateParams(body.build(), additionalHeaders.build(), additionalQueryParams.build()) + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(name, objectId, objectType, viewType, deletedAt, options, userId, viewData, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{name=$name, objectId=$objectId, objectType=$objectType, viewType=$viewType, deletedAt=$deletedAt, options=$options, userId=$userId, viewData=$viewData, additionalProperties=$additionalProperties}" } /** Type of table that the view corresponds to. */ diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewData.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewData.kt index 60697d88..9854e113 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewData.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewData.kt @@ -6,29 +6,28 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull /** The view definition */ -@NoAutoDetect class ViewData -@JsonCreator private constructor( - @JsonProperty("search") - @ExcludeMissing - private val search: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val search: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("search") @ExcludeMissing search: JsonField = JsonMissing.of() + ) : this(search, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -42,20 +41,15 @@ private constructor( */ @JsonProperty("search") @ExcludeMissing fun _search(): JsonField = search + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): ViewData = apply { - if (validated) { - return@apply - } - - search().ifPresent { it.validate() } - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -115,7 +109,18 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): ViewData = ViewData(search, additionalProperties.toImmutable()) + fun build(): ViewData = ViewData(search, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): ViewData = apply { + if (validated) { + return@apply + } + + search().ifPresent { it.validate() } + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDataSearch.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDataSearch.kt index 35428978..e621ac3b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDataSearch.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDataSearch.kt @@ -6,38 +6,39 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkKnown -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -@NoAutoDetect class ViewDataSearch -@JsonCreator private constructor( - @JsonProperty("filter") - @ExcludeMissing - private val filter: JsonField> = JsonMissing.of(), - @JsonProperty("match") - @ExcludeMissing - private val match: JsonField> = JsonMissing.of(), - @JsonProperty("sort") - @ExcludeMissing - private val sort: JsonField> = JsonMissing.of(), - @JsonProperty("tag") - @ExcludeMissing - private val tag: JsonField> = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val filter: JsonField>, + private val match: JsonField>, + private val sort: JsonField>, + private val tag: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("filter") + @ExcludeMissing + filter: JsonField> = JsonMissing.of(), + @JsonProperty("match") + @ExcludeMissing + match: JsonField> = JsonMissing.of(), + @JsonProperty("sort") @ExcludeMissing sort: JsonField> = JsonMissing.of(), + @JsonProperty("tag") @ExcludeMissing tag: JsonField> = JsonMissing.of(), + ) : this(filter, match, sort, tag, mutableMapOf()) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -90,23 +91,15 @@ private constructor( */ @JsonProperty("tag") @ExcludeMissing fun _tag(): JsonField> = tag + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): ViewDataSearch = apply { - if (validated) { - return@apply - } - - filter() - match() - sort() - tag() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -274,10 +267,24 @@ private constructor( (match ?: JsonMissing.of()).map { it.toImmutable() }, (sort ?: JsonMissing.of()).map { it.toImmutable() }, (tag ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } + private var validated: Boolean = false + + fun validate(): ViewDataSearch = apply { + if (validated) { + return@apply + } + + filter() + match() + sort() + tag() + validated = true + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDeleteParams.kt index 78d16f80..6c0fbabe 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDeleteParams.kt @@ -6,18 +6,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects /** Delete a view object by its id */ @@ -68,194 +66,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - fun _pathParam(index: Int): String = - when (index) { - 0 -> viewId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams - - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("object_id") - @ExcludeMissing - private val objectId: JsonField = JsonMissing.of(), - @JsonProperty("object_type") - @ExcludeMissing - private val objectType: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { - - /** - * The id of the object the view applies to - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun objectId(): String = objectId.getRequired("object_id") - - /** - * The object type that the ACL applies to - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun objectType(): AclObjectType = objectType.getRequired("object_type") - - /** - * Returns the raw JSON value of [objectId]. - * - * Unlike [objectId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("object_id") @ExcludeMissing fun _objectId(): JsonField = objectId - - /** - * Returns the raw JSON value of [objectType]. - * - * Unlike [objectType], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("object_type") - @ExcludeMissing - fun _objectType(): JsonField = objectType - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): Body = apply { - if (validated) { - return@apply - } - - objectId() - objectType() - validated = true - } - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .objectId() - * .objectType() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Body]. */ - class Builder internal constructor() { - - private var objectId: JsonField? = null - private var objectType: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - objectId = body.objectId - objectType = body.objectType - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** The id of the object the view applies to */ - fun objectId(objectId: String) = objectId(JsonField.of(objectId)) - - /** - * Sets [Builder.objectId] to an arbitrary JSON value. - * - * You should usually call [Builder.objectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun objectId(objectId: JsonField) = apply { this.objectId = objectId } - - /** The object type that the ACL applies to */ - fun objectType(objectType: AclObjectType) = objectType(JsonField.of(objectType)) - - /** - * Sets [Builder.objectType] to an arbitrary JSON value. - * - * You should usually call [Builder.objectType] with a well-typed [AclObjectType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun objectType(objectType: JsonField) = apply { - this.objectType = objectType - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - 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) - } - - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .objectId() - * .objectType() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("objectId", objectId), - checkRequired("objectType", objectType), - additionalProperties.toImmutable(), - ) - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Body && objectId == other.objectId && objectType == other.objectType && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(objectId, objectType, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Body{objectId=$objectId, objectType=$objectType, additionalProperties=$additionalProperties}" - } - fun toBuilder() = Builder().from(this) companion object { @@ -274,7 +84,6 @@ private constructor( } /** A builder for [ViewDeleteParams]. */ - @NoAutoDetect class Builder internal constructor() { private var viewId: String? = null @@ -456,6 +265,203 @@ private constructor( ) } + @JvmSynthetic internal fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> viewId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val objectId: JsonField, + private val objectType: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("object_id") + @ExcludeMissing + objectId: JsonField = JsonMissing.of(), + @JsonProperty("object_type") + @ExcludeMissing + objectType: JsonField = JsonMissing.of(), + ) : this(objectId, objectType, mutableMapOf()) + + /** + * The id of the object the view applies to + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun objectId(): String = objectId.getRequired("object_id") + + /** + * The object type that the ACL applies to + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun objectType(): AclObjectType = objectType.getRequired("object_type") + + /** + * Returns the raw JSON value of [objectId]. + * + * Unlike [objectId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("object_id") @ExcludeMissing fun _objectId(): JsonField = objectId + + /** + * Returns the raw JSON value of [objectType]. + * + * Unlike [objectType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("object_type") + @ExcludeMissing + fun _objectType(): JsonField = objectType + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .objectId() + * .objectType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var objectId: JsonField? = null + private var objectType: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + objectId = body.objectId + objectType = body.objectType + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** The id of the object the view applies to */ + fun objectId(objectId: String) = objectId(JsonField.of(objectId)) + + /** + * Sets [Builder.objectId] to an arbitrary JSON value. + * + * You should usually call [Builder.objectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun objectId(objectId: JsonField) = apply { this.objectId = objectId } + + /** The object type that the ACL applies to */ + fun objectType(objectType: AclObjectType) = objectType(JsonField.of(objectType)) + + /** + * Sets [Builder.objectType] to an arbitrary JSON value. + * + * You should usually call [Builder.objectType] with a well-typed [AclObjectType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun objectType(objectType: JsonField) = apply { + this.objectType = objectType + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .objectId() + * .objectType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("objectId", objectId), + checkRequired("objectType", objectType), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + objectId() + objectType() + validated = true + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && objectId == other.objectId && objectType == other.objectType && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(objectId, objectType, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{objectId=$objectId, objectType=$objectType, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt index cd5fd5b9..371fc6e7 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.blocking.ViewService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -81,23 +79,30 @@ private constructor( ViewListPage(viewsService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -155,7 +160,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt index e02a4656..a3879aa6 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt @@ -6,14 +6,12 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.services.async.ViewServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -83,23 +81,30 @@ private constructor( ViewListPageAsync(viewsService, params, response) } - @NoAutoDetect - class Response - @JsonCreator - constructor( - @JsonProperty("objects") private val objects: JsonField> = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), + class Response( + private val objects: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("objects") objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + fun objects(): List = objects.getNullable("objects") ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) private var validated: Boolean = false @@ -157,7 +162,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Response = Response(objects, additionalProperties.toImmutable()) + fun build(): Response = Response(objects, additionalProperties.toMutableMap()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListParams.kt index 26430c16..67a9b81b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListParams.kt @@ -5,7 +5,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.BaseDeserializer import com.braintrustdata.api.core.BaseSerializer import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow @@ -84,33 +83,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = - QueryParams.builder() - .apply { - put("object_id", objectId) - put("object_type", objectType.toString()) - endingBefore?.let { put("ending_before", it) } - ids?.accept( - object : Ids.Visitor { - override fun visitString(string: String) { - put("ids", string) - } - - override fun visitStrings(strings: List) { - put("ids", strings.joinToString(",")) - } - } - ) - limit?.let { put("limit", it.toString()) } - startingAfter?.let { put("starting_after", it) } - viewName?.let { put("view_name", it) } - viewType?.let { put("view_type", it.toString()) } - putAll(additionalQueryParams) - } - .build() - fun toBuilder() = Builder().from(this) companion object { @@ -128,7 +100,6 @@ private constructor( } /** A builder for [ViewListParams]. */ - @NoAutoDetect class Builder internal constructor() { private var objectId: String? = null @@ -353,6 +324,33 @@ private constructor( ) } + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + put("object_id", objectId) + put("object_type", objectType.toString()) + endingBefore?.let { put("ending_before", it) } + ids?.accept( + object : Ids.Visitor { + override fun visitString(string: String) { + put("ids", string) + } + + override fun visitStrings(strings: List) { + put("ids", strings.joinToString(",")) + } + } + ) + limit?.let { put("limit", it.toString()) } + startingAfter?.let { put("starting_after", it) } + viewName?.let { put("view_name", it) } + viewType?.let { put("view_type", it.toString()) } + putAll(additionalQueryParams) + } + .build() + /** * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewOptions.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewOptions.kt index bf4af30f..14f15eb4 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewOptions.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewOptions.kt @@ -6,45 +6,54 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.checkKnown -import com.braintrustdata.api.core.immutableEmptyMap import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Options for the view in the app */ -@NoAutoDetect class ViewOptions -@JsonCreator private constructor( - @JsonProperty("columnOrder") - @ExcludeMissing - private val columnOrder: JsonField> = JsonMissing.of(), - @JsonProperty("columnSizing") - @ExcludeMissing - private val columnSizing: JsonField = JsonMissing.of(), - @JsonProperty("columnVisibility") - @ExcludeMissing - private val columnVisibility: JsonField = JsonMissing.of(), - @JsonProperty("grouping") - @ExcludeMissing - private val grouping: JsonField = JsonMissing.of(), - @JsonProperty("layout") - @ExcludeMissing - private val layout: JsonField = JsonMissing.of(), - @JsonProperty("rowHeight") - @ExcludeMissing - private val rowHeight: JsonField = JsonMissing.of(), - @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), + private val columnOrder: JsonField>, + private val columnSizing: JsonField, + private val columnVisibility: JsonField, + private val grouping: JsonField, + private val layout: JsonField, + private val rowHeight: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("columnOrder") + @ExcludeMissing + columnOrder: JsonField> = JsonMissing.of(), + @JsonProperty("columnSizing") + @ExcludeMissing + columnSizing: JsonField = JsonMissing.of(), + @JsonProperty("columnVisibility") + @ExcludeMissing + columnVisibility: JsonField = JsonMissing.of(), + @JsonProperty("grouping") @ExcludeMissing grouping: JsonField = JsonMissing.of(), + @JsonProperty("layout") @ExcludeMissing layout: JsonField = JsonMissing.of(), + @JsonProperty("rowHeight") @ExcludeMissing rowHeight: JsonField = JsonMissing.of(), + ) : this( + columnOrder, + columnSizing, + columnVisibility, + grouping, + layout, + rowHeight, + mutableMapOf(), + ) + /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -133,25 +142,15 @@ private constructor( */ @JsonProperty("rowHeight") @ExcludeMissing fun _rowHeight(): JsonField = rowHeight + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): ViewOptions = apply { - if (validated) { - return@apply - } - - columnOrder() - columnSizing().ifPresent { it.validate() } - columnVisibility().ifPresent { it.validate() } - grouping() - layout() - rowHeight() - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -319,32 +318,41 @@ private constructor( grouping, layout, rowHeight, - additionalProperties.toImmutable(), + additionalProperties.toMutableMap(), ) } - @NoAutoDetect - class ColumnSizing - @JsonCreator - private constructor( - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private var validated: Boolean = false - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun validate(): ViewOptions = apply { + if (validated) { + return@apply + } - private var validated: Boolean = false + columnOrder() + columnSizing().ifPresent { it.validate() } + columnVisibility().ifPresent { it.validate() } + grouping() + layout() + rowHeight() + validated = true + } - fun validate(): ColumnSizing = apply { - if (validated) { - return@apply - } + class ColumnSizing + private constructor(private val additionalProperties: MutableMap) { - validated = true + @JsonCreator private constructor() : this(mutableMapOf()) + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + fun toBuilder() = Builder().from(this) companion object { @@ -387,7 +395,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): ColumnSizing = ColumnSizing(additionalProperties.toImmutable()) + fun build(): ColumnSizing = ColumnSizing(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): ColumnSizing = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { @@ -407,27 +425,20 @@ private constructor( override fun toString() = "ColumnSizing{additionalProperties=$additionalProperties}" } - @NoAutoDetect class ColumnVisibility - @JsonCreator - private constructor( + private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap() - ) { + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - private var validated: Boolean = false - - fun validate(): ColumnVisibility = apply { - if (validated) { - return@apply - } - - validated = true - } + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -471,7 +482,17 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): ColumnVisibility = ColumnVisibility(additionalProperties.toImmutable()) + fun build(): ColumnVisibility = ColumnVisibility(additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): ColumnVisibility = apply { + if (validated) { + return@apply + } + + validated = true } override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewReplaceParams.kt index 8f84c8c9..95d8a7ae 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewReplaceParams.kt @@ -7,19 +7,17 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.time.OffsetDateTime +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -161,422 +159,267 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams + fun toBuilder() = Builder().from(this) - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("object_id") - @ExcludeMissing - private val objectId: JsonField = JsonMissing.of(), - @JsonProperty("object_type") - @ExcludeMissing - private val objectType: JsonField = JsonMissing.of(), - @JsonProperty("view_type") - @ExcludeMissing - private val viewType: JsonField = JsonMissing.of(), - @JsonProperty("deleted_at") - @ExcludeMissing - private val deletedAt: JsonField = JsonMissing.of(), - @JsonProperty("options") - @ExcludeMissing - private val options: JsonField = JsonMissing.of(), - @JsonProperty("user_id") - @ExcludeMissing - private val userId: JsonField = JsonMissing.of(), - @JsonProperty("view_data") - @ExcludeMissing - private val viewData: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + companion object { /** - * Name of the view + * Returns a mutable builder for constructing an instance of [ViewReplaceParams]. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + * The following fields are required: + * ```java + * .name() + * .objectId() + * .objectType() + * .viewType() + * ``` */ - fun name(): String = name.getRequired("name") + @JvmStatic fun builder() = Builder() + } - /** - * The id of the object the view applies to - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun objectId(): String = objectId.getRequired("object_id") + /** A builder for [ViewReplaceParams]. */ + class Builder internal constructor() { - /** - * The object type that the ACL applies to - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun objectType(): AclObjectType = objectType.getRequired("object_type") + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - /** - * Type of table that the view corresponds to. - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun viewType(): Optional = Optional.ofNullable(viewType.getNullable("view_type")) + @JvmSynthetic + internal fun from(viewReplaceParams: ViewReplaceParams) = apply { + body = viewReplaceParams.body.toBuilder() + additionalHeaders = viewReplaceParams.additionalHeaders.toBuilder() + additionalQueryParams = viewReplaceParams.additionalQueryParams.toBuilder() + } - /** - * Date of role deletion, or null if the role is still active - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun deletedAt(): Optional = - Optional.ofNullable(deletedAt.getNullable("deleted_at")) + /** Name of the view */ + fun name(name: String) = apply { body.name(name) } /** - * Options for the view in the app + * Sets [Builder.name] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun options(): Optional = Optional.ofNullable(options.getNullable("options")) + fun name(name: JsonField) = apply { body.name(name) } - /** - * Identifies the user who created the view - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) + /** The id of the object the view applies to */ + fun objectId(objectId: String) = apply { body.objectId(objectId) } /** - * The view definition + * Sets [Builder.objectId] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.objectId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun viewData(): Optional = Optional.ofNullable(viewData.getNullable("view_data")) + fun objectId(objectId: JsonField) = apply { body.objectId(objectId) } - /** - * Returns the raw JSON value of [name]. - * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + /** The object type that the ACL applies to */ + fun objectType(objectType: AclObjectType) = apply { body.objectType(objectType) } /** - * Returns the raw JSON value of [objectId]. + * Sets [Builder.objectType] to an arbitrary JSON value. * - * Unlike [objectId], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.objectType] with a well-typed [AclObjectType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("object_id") @ExcludeMissing fun _objectId(): JsonField = objectId + fun objectType(objectType: JsonField) = apply { body.objectType(objectType) } - /** - * Returns the raw JSON value of [objectType]. - * - * Unlike [objectType], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("object_type") - @ExcludeMissing - fun _objectType(): JsonField = objectType + /** Type of table that the view corresponds to. */ + fun viewType(viewType: ViewType?) = apply { body.viewType(viewType) } + + /** Alias for calling [Builder.viewType] with `viewType.orElse(null)`. */ + fun viewType(viewType: Optional) = viewType(viewType.getOrNull()) /** - * Returns the raw JSON value of [viewType]. + * Sets [Builder.viewType] to an arbitrary JSON value. * - * Unlike [viewType], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.viewType] with a well-typed [ViewType] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("view_type") @ExcludeMissing fun _viewType(): JsonField = viewType + fun viewType(viewType: JsonField) = apply { body.viewType(viewType) } + + /** Date of role deletion, or null if the role is still active */ + fun deletedAt(deletedAt: OffsetDateTime?) = apply { body.deletedAt(deletedAt) } + + /** Alias for calling [Builder.deletedAt] with `deletedAt.orElse(null)`. */ + fun deletedAt(deletedAt: Optional) = deletedAt(deletedAt.getOrNull()) /** - * Returns the raw JSON value of [deletedAt]. + * Sets [Builder.deletedAt] to an arbitrary JSON value. * - * Unlike [deletedAt], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.deletedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("deleted_at") - @ExcludeMissing - fun _deletedAt(): JsonField = deletedAt + fun deletedAt(deletedAt: JsonField) = apply { body.deletedAt(deletedAt) } + + /** Options for the view in the app */ + fun options(options: ViewOptions?) = apply { body.options(options) } + + /** Alias for calling [Builder.options] with `options.orElse(null)`. */ + fun options(options: Optional) = options(options.getOrNull()) /** - * Returns the raw JSON value of [options]. + * Sets [Builder.options] to an arbitrary JSON value. * - * Unlike [options], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.options] with a well-typed [ViewOptions] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("options") @ExcludeMissing fun _options(): JsonField = options + fun options(options: JsonField) = apply { body.options(options) } + + /** Identifies the user who created the view */ + fun userId(userId: String?) = apply { body.userId(userId) } + + /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ + fun userId(userId: Optional) = userId(userId.getOrNull()) /** - * Returns the raw JSON value of [userId]. + * Sets [Builder.userId] to an arbitrary JSON value. * - * Unlike [userId], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.userId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + fun userId(userId: JsonField) = apply { body.userId(userId) } + + /** The view definition */ + fun viewData(viewData: ViewData?) = apply { body.viewData(viewData) } + + /** Alias for calling [Builder.viewData] with `viewData.orElse(null)`. */ + fun viewData(viewData: Optional) = viewData(viewData.getOrNull()) /** - * Returns the raw JSON value of [viewData]. + * Sets [Builder.viewData] to an arbitrary JSON value. * - * Unlike [viewData], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.viewData] with a well-typed [ViewData] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("view_data") @ExcludeMissing fun _viewData(): JsonField = viewData + fun viewData(viewData: JsonField) = apply { body.viewData(viewData) } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } - private var validated: Boolean = false + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } - fun validate(): Body = apply { - if (validated) { - return@apply + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) } - name() - objectId() - objectType() - viewType() - deletedAt() - options().ifPresent { it.validate() } - userId() - viewData().ifPresent { it.validate() } - validated = true + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) } - fun toBuilder() = Builder().from(this) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - companion object { + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .name() - * .objectId() - * .objectType() - * .viewType() - * ``` - */ - @JvmStatic fun builder() = Builder() + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - /** A builder for [Body]. */ - class Builder internal constructor() { + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - private var name: JsonField? = null - private var objectId: JsonField? = null - private var objectType: JsonField? = null - private var viewType: JsonField? = null - private var deletedAt: JsonField = JsonMissing.of() - private var options: JsonField = JsonMissing.of() - private var userId: JsonField = JsonMissing.of() - private var viewData: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(body: Body) = apply { - name = body.name - objectId = body.objectId - objectType = body.objectType - viewType = body.viewType - deletedAt = body.deletedAt - options = body.options - userId = body.userId - viewData = body.viewData - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** Name of the view */ - fun name(name: String) = name(JsonField.of(name)) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } - - /** The id of the object the view applies to */ - fun objectId(objectId: String) = objectId(JsonField.of(objectId)) - - /** - * Sets [Builder.objectId] to an arbitrary JSON value. - * - * You should usually call [Builder.objectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun objectId(objectId: JsonField) = apply { this.objectId = objectId } - - /** The object type that the ACL applies to */ - fun objectType(objectType: AclObjectType) = objectType(JsonField.of(objectType)) - - /** - * Sets [Builder.objectType] to an arbitrary JSON value. - * - * You should usually call [Builder.objectType] with a well-typed [AclObjectType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun objectType(objectType: JsonField) = apply { - this.objectType = objectType - } - - /** Type of table that the view corresponds to. */ - fun viewType(viewType: ViewType?) = viewType(JsonField.ofNullable(viewType)) - - /** Alias for calling [Builder.viewType] with `viewType.orElse(null)`. */ - fun viewType(viewType: Optional) = viewType(viewType.getOrNull()) - - /** - * Sets [Builder.viewType] to an arbitrary JSON value. - * - * You should usually call [Builder.viewType] with a well-typed [ViewType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun viewType(viewType: JsonField) = apply { this.viewType = viewType } - - /** Date of role deletion, or null if the role is still active */ - fun deletedAt(deletedAt: OffsetDateTime?) = deletedAt(JsonField.ofNullable(deletedAt)) - - /** Alias for calling [Builder.deletedAt] with `deletedAt.orElse(null)`. */ - fun deletedAt(deletedAt: Optional) = deletedAt(deletedAt.getOrNull()) - - /** - * Sets [Builder.deletedAt] to an arbitrary JSON value. - * - * You should usually call [Builder.deletedAt] with a well-typed [OffsetDateTime] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun deletedAt(deletedAt: JsonField) = apply { - this.deletedAt = deletedAt - } - - /** Options for the view in the app */ - fun options(options: ViewOptions?) = options(JsonField.ofNullable(options)) - - /** Alias for calling [Builder.options] with `options.orElse(null)`. */ - fun options(options: Optional) = options(options.getOrNull()) - - /** - * Sets [Builder.options] to an arbitrary JSON value. - * - * You should usually call [Builder.options] with a well-typed [ViewOptions] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun options(options: JsonField) = apply { this.options = options } + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** Identifies the user who created the view */ - fun userId(userId: String?) = userId(JsonField.ofNullable(userId)) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ - fun userId(userId: Optional) = userId(userId.getOrNull()) + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - /** - * Sets [Builder.userId] to an arbitrary JSON value. - * - * You should usually call [Builder.userId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun userId(userId: JsonField) = apply { this.userId = userId } + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** The view definition */ - fun viewData(viewData: ViewData?) = viewData(JsonField.ofNullable(viewData)) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** Alias for calling [Builder.viewData] with `viewData.orElse(null)`. */ - fun viewData(viewData: Optional) = viewData(viewData.getOrNull()) + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Sets [Builder.viewData] to an arbitrary JSON value. - * - * You should usually call [Builder.viewData] with a well-typed [ViewData] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun viewData(viewData: JsonField) = apply { this.viewData = viewData } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * .objectId() - * .objectType() - * .viewType() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("name", name), - checkRequired("objectId", objectId), - checkRequired("objectType", objectType), - checkRequired("viewType", viewType), - deletedAt, - options, - userId, - viewData, - additionalProperties.toImmutable(), - ) + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - return /* spotless:off */ other is Body && name == other.name && objectId == other.objectId && objectType == other.objectType && viewType == other.viewType && deletedAt == other.deletedAt && options == other.options && userId == other.userId && viewData == other.viewData && additionalProperties == other.additionalProperties /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, objectId, objectType, viewType, deletedAt, options, userId, viewData, additionalProperties) } - /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } - override fun hashCode(): Int = hashCode + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - override fun toString() = - "Body{name=$name, objectId=$objectId, objectType=$objectType, viewType=$viewType, deletedAt=$deletedAt, options=$options, userId=$userId, viewData=$viewData, additionalProperties=$additionalProperties}" - } + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - fun toBuilder() = Builder().from(this) + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - companion object { + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } /** - * Returns a mutable builder for constructing an instance of [ViewReplaceParams]. + * Returns an immutable instance of [ViewReplaceParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java @@ -585,271 +428,446 @@ private constructor( * .objectType() * .viewType() * ``` + * + * @throws IllegalStateException if any required field is unset. */ - @JvmStatic fun builder() = Builder() + fun build(): ViewReplaceParams = + ViewReplaceParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) } - /** A builder for [ViewReplaceParams]. */ - @NoAutoDetect - class Builder internal constructor() { + @JvmSynthetic internal fun _body(): Body = body - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun from(viewReplaceParams: ViewReplaceParams) = apply { - body = viewReplaceParams.body.toBuilder() - additionalHeaders = viewReplaceParams.additionalHeaders.toBuilder() - additionalQueryParams = viewReplaceParams.additionalQueryParams.toBuilder() - } + override fun _queryParams(): QueryParams = additionalQueryParams - /** Name of the view */ - fun name(name: String) = apply { body.name(name) } + class Body + private constructor( + private val name: JsonField, + private val objectId: JsonField, + private val objectType: JsonField, + private val viewType: JsonField, + private val deletedAt: JsonField, + private val options: JsonField, + private val userId: JsonField, + private val viewData: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("object_id") + @ExcludeMissing + objectId: JsonField = JsonMissing.of(), + @JsonProperty("object_type") + @ExcludeMissing + objectType: JsonField = JsonMissing.of(), + @JsonProperty("view_type") + @ExcludeMissing + viewType: JsonField = JsonMissing.of(), + @JsonProperty("deleted_at") + @ExcludeMissing + deletedAt: JsonField = JsonMissing.of(), + @JsonProperty("options") + @ExcludeMissing + options: JsonField = JsonMissing.of(), + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), + @JsonProperty("view_data") + @ExcludeMissing + viewData: JsonField = JsonMissing.of(), + ) : this( + name, + objectId, + objectType, + viewType, + deletedAt, + options, + userId, + viewData, + mutableMapOf(), + ) /** - * Sets [Builder.name] to an arbitrary JSON value. + * Name of the view * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun name(name: JsonField) = apply { body.name(name) } - - /** The id of the object the view applies to */ - fun objectId(objectId: String) = apply { body.objectId(objectId) } + fun name(): String = name.getRequired("name") /** - * Sets [Builder.objectId] to an arbitrary JSON value. + * The id of the object the view applies to * - * You should usually call [Builder.objectId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun objectId(objectId: JsonField) = apply { body.objectId(objectId) } - - /** The object type that the ACL applies to */ - fun objectType(objectType: AclObjectType) = apply { body.objectType(objectType) } + fun objectId(): String = objectId.getRequired("object_id") /** - * Sets [Builder.objectType] to an arbitrary JSON value. + * The object type that the ACL applies to * - * You should usually call [Builder.objectType] with a well-typed [AclObjectType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun objectType(objectType: JsonField) = apply { body.objectType(objectType) } - - /** Type of table that the view corresponds to. */ - fun viewType(viewType: ViewType?) = apply { body.viewType(viewType) } - - /** Alias for calling [Builder.viewType] with `viewType.orElse(null)`. */ - fun viewType(viewType: Optional) = viewType(viewType.getOrNull()) + fun objectType(): AclObjectType = objectType.getRequired("object_type") /** - * Sets [Builder.viewType] to an arbitrary JSON value. + * Type of table that the view corresponds to. * - * You should usually call [Builder.viewType] with a well-typed [ViewType] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun viewType(viewType: JsonField) = apply { body.viewType(viewType) } + fun viewType(): Optional = Optional.ofNullable(viewType.getNullable("view_type")) - /** Date of role deletion, or null if the role is still active */ - fun deletedAt(deletedAt: OffsetDateTime?) = apply { body.deletedAt(deletedAt) } + /** + * Date of role deletion, or null if the role is still active + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun deletedAt(): Optional = + Optional.ofNullable(deletedAt.getNullable("deleted_at")) - /** Alias for calling [Builder.deletedAt] with `deletedAt.orElse(null)`. */ - fun deletedAt(deletedAt: Optional) = deletedAt(deletedAt.getOrNull()) + /** + * Options for the view in the app + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun options(): Optional = Optional.ofNullable(options.getNullable("options")) /** - * Sets [Builder.deletedAt] to an arbitrary JSON value. + * Identifies the user who created the view * - * You should usually call [Builder.deletedAt] with a well-typed [OffsetDateTime] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun deletedAt(deletedAt: JsonField) = apply { body.deletedAt(deletedAt) } + fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) - /** Options for the view in the app */ - fun options(options: ViewOptions?) = apply { body.options(options) } + /** + * The view definition + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun viewData(): Optional = Optional.ofNullable(viewData.getNullable("view_data")) - /** Alias for calling [Builder.options] with `options.orElse(null)`. */ - fun options(options: Optional) = options(options.getOrNull()) + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name /** - * Sets [Builder.options] to an arbitrary JSON value. + * Returns the raw JSON value of [objectId]. * - * You should usually call [Builder.options] with a well-typed [ViewOptions] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [objectId], this method doesn't throw if the JSON field has an unexpected type. */ - fun options(options: JsonField) = apply { body.options(options) } + @JsonProperty("object_id") @ExcludeMissing fun _objectId(): JsonField = objectId - /** Identifies the user who created the view */ - fun userId(userId: String?) = apply { body.userId(userId) } + /** + * Returns the raw JSON value of [objectType]. + * + * Unlike [objectType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("object_type") + @ExcludeMissing + fun _objectType(): JsonField = objectType - /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ - fun userId(userId: Optional) = userId(userId.getOrNull()) + /** + * Returns the raw JSON value of [viewType]. + * + * Unlike [viewType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("view_type") @ExcludeMissing fun _viewType(): JsonField = viewType /** - * Sets [Builder.userId] to an arbitrary JSON value. + * Returns the raw JSON value of [deletedAt]. * - * You should usually call [Builder.userId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [deletedAt], this method doesn't throw if the JSON field has an unexpected type. */ - fun userId(userId: JsonField) = apply { body.userId(userId) } + @JsonProperty("deleted_at") + @ExcludeMissing + fun _deletedAt(): JsonField = deletedAt - /** The view definition */ - fun viewData(viewData: ViewData?) = apply { body.viewData(viewData) } + /** + * Returns the raw JSON value of [options]. + * + * Unlike [options], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("options") @ExcludeMissing fun _options(): JsonField = options - /** Alias for calling [Builder.viewData] with `viewData.orElse(null)`. */ - fun viewData(viewData: Optional) = viewData(viewData.getOrNull()) + /** + * Returns the raw JSON value of [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId /** - * Sets [Builder.viewData] to an arbitrary JSON value. + * Returns the raw JSON value of [viewData]. * - * You should usually call [Builder.viewData] with a well-typed [ViewData] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [viewData], this method doesn't throw if the JSON field has an unexpected type. */ - fun viewData(viewData: JsonField) = apply { body.viewData(viewData) } + @JsonProperty("view_data") @ExcludeMissing fun _viewData(): JsonField = viewData - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .name() + * .objectId() + * .objectType() + * .viewType() + * ``` + */ + @JvmStatic fun builder() = Builder() } - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var name: JsonField? = null + private var objectId: JsonField? = null + private var objectType: JsonField? = null + private var viewType: JsonField? = null + private var deletedAt: JsonField = JsonMissing.of() + private var options: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var viewData: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + name = body.name + objectId = body.objectId + objectType = body.objectType + viewType = body.viewType + deletedAt = body.deletedAt + options = body.options + userId = body.userId + viewData = body.viewData + additionalProperties = body.additionalProperties.toMutableMap() } - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + /** Name of the view */ + fun name(name: String) = name(JsonField.of(name)) - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** The id of the object the view applies to */ + fun objectId(objectId: String) = objectId(JsonField.of(objectId)) - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * Sets [Builder.objectId] to an arbitrary JSON value. + * + * You should usually call [Builder.objectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun objectId(objectId: JsonField) = apply { this.objectId = objectId } - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } + /** The object type that the ACL applies to */ + fun objectType(objectType: AclObjectType) = objectType(JsonField.of(objectType)) - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } + /** + * Sets [Builder.objectType] to an arbitrary JSON value. + * + * You should usually call [Builder.objectType] with a well-typed [AclObjectType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun objectType(objectType: JsonField) = apply { + this.objectType = objectType + } - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** Type of table that the view corresponds to. */ + fun viewType(viewType: ViewType?) = viewType(JsonField.ofNullable(viewType)) - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** Alias for calling [Builder.viewType] with `viewType.orElse(null)`. */ + fun viewType(viewType: Optional) = viewType(viewType.getOrNull()) - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } + /** + * Sets [Builder.viewType] to an arbitrary JSON value. + * + * You should usually call [Builder.viewType] with a well-typed [ViewType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun viewType(viewType: JsonField) = apply { this.viewType = viewType } - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } + /** Date of role deletion, or null if the role is still active */ + fun deletedAt(deletedAt: OffsetDateTime?) = deletedAt(JsonField.ofNullable(deletedAt)) - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** Alias for calling [Builder.deletedAt] with `deletedAt.orElse(null)`. */ + fun deletedAt(deletedAt: Optional) = deletedAt(deletedAt.getOrNull()) - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** + * Sets [Builder.deletedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.deletedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun deletedAt(deletedAt: JsonField) = apply { + this.deletedAt = deletedAt + } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + /** Options for the view in the app */ + fun options(options: ViewOptions?) = options(JsonField.ofNullable(options)) - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } + /** Alias for calling [Builder.options] with `options.orElse(null)`. */ + fun options(options: Optional) = options(options.getOrNull()) - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + /** + * Sets [Builder.options] to an arbitrary JSON value. + * + * You should usually call [Builder.options] with a well-typed [ViewOptions] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun options(options: JsonField) = apply { this.options = options } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + /** Identifies the user who created the view */ + fun userId(userId: String?) = userId(JsonField.ofNullable(userId)) - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } + /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ + fun userId(userId: Optional) = userId(userId.getOrNull()) - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) - } + /** + * Sets [Builder.userId] to an arbitrary JSON value. + * + * You should usually call [Builder.userId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun userId(userId: JsonField) = apply { this.userId = userId } - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } + /** The view definition */ + fun viewData(viewData: ViewData?) = viewData(JsonField.ofNullable(viewData)) - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + /** Alias for calling [Builder.viewData] with `viewData.orElse(null)`. */ + fun viewData(viewData: Optional) = viewData(viewData.getOrNull()) + + /** + * Sets [Builder.viewData] to an arbitrary JSON value. + * + * You should usually call [Builder.viewData] with a well-typed [ViewData] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun viewData(viewData: JsonField) = apply { this.viewData = viewData } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) } - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * .objectId() + * .objectType() + * .viewType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("name", name), + checkRequired("objectId", objectId), + checkRequired("objectType", objectType), + checkRequired("viewType", viewType), + deletedAt, + options, + userId, + viewData, + additionalProperties.toMutableMap(), + ) } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply } - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + name() + objectId() + objectType() + viewType() + deletedAt() + options().ifPresent { it.validate() } + userId() + viewData().ifPresent { it.validate() } + validated = true + } - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && name == other.name && objectId == other.objectId && objectType == other.objectType && viewType == other.viewType && deletedAt == other.deletedAt && options == other.options && userId == other.userId && viewData == other.viewData && additionalProperties == other.additionalProperties /* spotless:on */ } - /** - * Returns an immutable instance of [ViewReplaceParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .name() - * .objectId() - * .objectType() - * .viewType() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ViewReplaceParams = - ViewReplaceParams( - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(name, objectId, objectType, viewType, deletedAt, options, userId, viewData, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{name=$name, objectId=$objectId, objectType=$objectType, viewType=$viewType, deletedAt=$deletedAt, options=$options, userId=$userId, viewData=$viewData, additionalProperties=$additionalProperties}" } /** Type of table that the view corresponds to. */ diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewRetrieveParams.kt index ae36c399..7f27c2a4 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewRetrieveParams.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers @@ -32,23 +31,6 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _pathParam(index: Int): String = - when (index) { - 0 -> viewId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = - QueryParams.builder() - .apply { - put("object_id", objectId) - put("object_type", objectType.toString()) - putAll(additionalQueryParams) - } - .build() - fun toBuilder() = Builder().from(this) companion object { @@ -67,7 +49,6 @@ private constructor( } /** A builder for [ViewRetrieveParams]. */ - @NoAutoDetect class Builder internal constructor() { private var viewId: String? = null @@ -216,6 +197,23 @@ private constructor( ) } + fun _pathParam(index: Int): String = + when (index) { + 0 -> viewId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + put("object_id", objectId) + put("object_type", objectType.toString()) + putAll(additionalQueryParams) + } + .build() + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewUpdateParams.kt index 91b468bf..e92e3b34 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewUpdateParams.kt @@ -7,18 +7,16 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.core.NoAutoDetect import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.core.immutableEmptyMap -import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -150,385 +148,259 @@ private constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun _body(): Body = body - - fun _pathParam(index: Int): String = - when (index) { - 0 -> viewId - else -> "" - } - - override fun _headers(): Headers = additionalHeaders - - override fun _queryParams(): QueryParams = additionalQueryParams + fun toBuilder() = Builder().from(this) - @NoAutoDetect - class Body - @JsonCreator - private constructor( - @JsonProperty("object_id") - @ExcludeMissing - private val objectId: JsonField = JsonMissing.of(), - @JsonProperty("object_type") - @ExcludeMissing - private val objectType: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), - @JsonProperty("options") - @ExcludeMissing - private val options: JsonField = JsonMissing.of(), - @JsonProperty("user_id") - @ExcludeMissing - private val userId: JsonField = JsonMissing.of(), - @JsonProperty("view_data") - @ExcludeMissing - private val viewData: JsonField = JsonMissing.of(), - @JsonProperty("view_type") - @ExcludeMissing - private val viewType: JsonField = JsonMissing.of(), - @JsonAnySetter - private val additionalProperties: Map = immutableEmptyMap(), - ) { + companion object { /** - * The id of the object the view applies to + * Returns a mutable builder for constructing an instance of [ViewUpdateParams]. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + * The following fields are required: + * ```java + * .viewId() + * .objectId() + * .objectType() + * ``` */ - fun objectId(): String = objectId.getRequired("object_id") + @JvmStatic fun builder() = Builder() + } - /** - * The object type that the ACL applies to - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun objectType(): AclObjectType = objectType.getRequired("object_type") + /** A builder for [ViewUpdateParams]. */ + class Builder internal constructor() { - /** - * Name of the view - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + private var viewId: String? = null + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - /** - * Options for the view in the app - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun options(): Optional = Optional.ofNullable(options.getNullable("options")) + @JvmSynthetic + internal fun from(viewUpdateParams: ViewUpdateParams) = apply { + viewId = viewUpdateParams.viewId + body = viewUpdateParams.body.toBuilder() + additionalHeaders = viewUpdateParams.additionalHeaders.toBuilder() + additionalQueryParams = viewUpdateParams.additionalQueryParams.toBuilder() + } - /** - * Identifies the user who created the view - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) + /** View id */ + fun viewId(viewId: String) = apply { this.viewId = viewId } - /** - * The view definition - * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun viewData(): Optional = Optional.ofNullable(viewData.getNullable("view_data")) + /** The id of the object the view applies to */ + fun objectId(objectId: String) = apply { body.objectId(objectId) } /** - * Type of table that the view corresponds to. + * Sets [Builder.objectId] to an arbitrary JSON value. * - * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * You should usually call [Builder.objectId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun viewType(): Optional = Optional.ofNullable(viewType.getNullable("view_type")) + fun objectId(objectId: JsonField) = apply { body.objectId(objectId) } - /** - * Returns the raw JSON value of [objectId]. - * - * Unlike [objectId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("object_id") @ExcludeMissing fun _objectId(): JsonField = objectId + /** The object type that the ACL applies to */ + fun objectType(objectType: AclObjectType) = apply { body.objectType(objectType) } /** - * Returns the raw JSON value of [objectType]. + * Sets [Builder.objectType] to an arbitrary JSON value. * - * Unlike [objectType], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.objectType] with a well-typed [AclObjectType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - @JsonProperty("object_type") - @ExcludeMissing - fun _objectType(): JsonField = objectType + fun objectType(objectType: JsonField) = apply { body.objectType(objectType) } + + /** Name of the view */ + fun name(name: String?) = apply { body.name(name) } + + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) /** - * Returns the raw JSON value of [name]. + * Sets [Builder.name] to an arbitrary JSON value. * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + fun name(name: JsonField) = apply { body.name(name) } + + /** Options for the view in the app */ + fun options(options: ViewOptions?) = apply { body.options(options) } + + /** Alias for calling [Builder.options] with `options.orElse(null)`. */ + fun options(options: Optional) = options(options.getOrNull()) /** - * Returns the raw JSON value of [options]. + * Sets [Builder.options] to an arbitrary JSON value. * - * Unlike [options], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.options] with a well-typed [ViewOptions] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("options") @ExcludeMissing fun _options(): JsonField = options + fun options(options: JsonField) = apply { body.options(options) } + + /** Identifies the user who created the view */ + fun userId(userId: String?) = apply { body.userId(userId) } + + /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ + fun userId(userId: Optional) = userId(userId.getOrNull()) /** - * Returns the raw JSON value of [userId]. + * Sets [Builder.userId] to an arbitrary JSON value. * - * Unlike [userId], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.userId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + fun userId(userId: JsonField) = apply { body.userId(userId) } + + /** The view definition */ + fun viewData(viewData: ViewData?) = apply { body.viewData(viewData) } + + /** Alias for calling [Builder.viewData] with `viewData.orElse(null)`. */ + fun viewData(viewData: Optional) = viewData(viewData.getOrNull()) /** - * Returns the raw JSON value of [viewData]. + * Sets [Builder.viewData] to an arbitrary JSON value. * - * Unlike [viewData], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.viewData] with a well-typed [ViewData] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("view_data") @ExcludeMissing fun _viewData(): JsonField = viewData + fun viewData(viewData: JsonField) = apply { body.viewData(viewData) } + + /** Type of table that the view corresponds to. */ + fun viewType(viewType: ViewType?) = apply { body.viewType(viewType) } + + /** Alias for calling [Builder.viewType] with `viewType.orElse(null)`. */ + fun viewType(viewType: Optional) = viewType(viewType.getOrNull()) /** - * Returns the raw JSON value of [viewType]. + * Sets [Builder.viewType] to an arbitrary JSON value. * - * Unlike [viewType], this method doesn't throw if the JSON field has an unexpected type. + * You should usually call [Builder.viewType] with a well-typed [ViewType] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - @JsonProperty("view_type") @ExcludeMissing fun _viewType(): JsonField = viewType + fun viewType(viewType: JsonField) = apply { body.viewType(viewType) } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } - private var validated: Boolean = false + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } - fun validate(): Body = apply { - if (validated) { - return@apply + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) } - objectId() - objectType() - name() - options().ifPresent { it.validate() } - userId() - viewData().ifPresent { it.validate() } - viewType() - validated = true + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) } - fun toBuilder() = Builder().from(this) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - companion object { + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } - /** - * Returns a mutable builder for constructing an instance of [Body]. - * - * The following fields are required: - * ```java - * .objectId() - * .objectType() - * ``` - */ - @JvmStatic fun builder() = Builder() + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - /** A builder for [Body]. */ - class Builder internal constructor() { + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } - private var objectId: JsonField? = null - private var objectType: JsonField? = null - private var name: JsonField = JsonMissing.of() - private var options: JsonField = JsonMissing.of() - private var userId: JsonField = JsonMissing.of() - private var viewData: JsonField = JsonMissing.of() - private var viewType: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - @JvmSynthetic - internal fun from(body: Body) = apply { - objectId = body.objectId - objectType = body.objectType - name = body.name - options = body.options - userId = body.userId - viewData = body.viewData - viewType = body.viewType - additionalProperties = body.additionalProperties.toMutableMap() - } - - /** The id of the object the view applies to */ - fun objectId(objectId: String) = objectId(JsonField.of(objectId)) - - /** - * Sets [Builder.objectId] to an arbitrary JSON value. - * - * You should usually call [Builder.objectId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun objectId(objectId: JsonField) = apply { this.objectId = objectId } - - /** The object type that the ACL applies to */ - fun objectType(objectType: AclObjectType) = objectType(JsonField.of(objectType)) - - /** - * Sets [Builder.objectType] to an arbitrary JSON value. - * - * You should usually call [Builder.objectType] with a well-typed [AclObjectType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun objectType(objectType: JsonField) = apply { - this.objectType = objectType - } - - /** Name of the view */ - fun name(name: String?) = name(JsonField.ofNullable(name)) - - /** Alias for calling [Builder.name] with `name.orElse(null)`. */ - fun name(name: Optional) = name(name.getOrNull()) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun name(name: JsonField) = apply { this.name = name } - - /** Options for the view in the app */ - fun options(options: ViewOptions?) = options(JsonField.ofNullable(options)) - - /** Alias for calling [Builder.options] with `options.orElse(null)`. */ - fun options(options: Optional) = options(options.getOrNull()) - - /** - * Sets [Builder.options] to an arbitrary JSON value. - * - * You should usually call [Builder.options] with a well-typed [ViewOptions] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun options(options: JsonField) = apply { this.options = options } - - /** Identifies the user who created the view */ - fun userId(userId: String?) = userId(JsonField.ofNullable(userId)) - - /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ - fun userId(userId: Optional) = userId(userId.getOrNull()) - - /** - * Sets [Builder.userId] to an arbitrary JSON value. - * - * You should usually call [Builder.userId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun userId(userId: JsonField) = apply { this.userId = userId } - - /** The view definition */ - fun viewData(viewData: ViewData?) = viewData(JsonField.ofNullable(viewData)) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } - /** Alias for calling [Builder.viewData] with `viewData.orElse(null)`. */ - fun viewData(viewData: Optional) = viewData(viewData.getOrNull()) + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } - /** - * Sets [Builder.viewData] to an arbitrary JSON value. - * - * You should usually call [Builder.viewData] with a well-typed [ViewData] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun viewData(viewData: JsonField) = apply { this.viewData = viewData } + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } - /** Type of table that the view corresponds to. */ - fun viewType(viewType: ViewType?) = viewType(JsonField.ofNullable(viewType)) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** Alias for calling [Builder.viewType] with `viewType.orElse(null)`. */ - fun viewType(viewType: Optional) = viewType(viewType.getOrNull()) + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } - /** - * Sets [Builder.viewType] to an arbitrary JSON value. - * - * You should usually call [Builder.viewType] with a well-typed [ViewType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun viewType(viewType: JsonField) = apply { this.viewType = viewType } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } - /** - * Returns an immutable instance of [Body]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .objectId() - * .objectType() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Body = - Body( - checkRequired("objectId", objectId), - checkRequired("objectType", objectType), - name, - options, - userId, - viewData, - viewType, - additionalProperties.toImmutable(), - ) + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) } - return /* spotless:off */ other is Body && objectId == other.objectId && objectType == other.objectType && name == other.name && options == other.options && userId == other.userId && viewData == other.viewData && viewType == other.viewType && additionalProperties == other.additionalProperties /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(objectId, objectType, name, options, userId, viewData, viewType, additionalProperties) } - /* spotless:on */ + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } - override fun hashCode(): Int = hashCode + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - override fun toString() = - "Body{objectId=$objectId, objectType=$objectType, name=$name, options=$options, userId=$userId, viewData=$viewData, viewType=$viewType, additionalProperties=$additionalProperties}" - } + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } - fun toBuilder() = Builder().from(this) + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } - companion object { + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } /** - * Returns a mutable builder for constructing an instance of [ViewUpdateParams]. + * Returns an immutable instance of [ViewUpdateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java @@ -536,264 +408,399 @@ private constructor( * .objectId() * .objectType() * ``` + * + * @throws IllegalStateException if any required field is unset. */ - @JvmStatic fun builder() = Builder() + fun build(): ViewUpdateParams = + ViewUpdateParams( + checkRequired("viewId", viewId), + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) } - /** A builder for [ViewUpdateParams]. */ - @NoAutoDetect - class Builder internal constructor() { - - private var viewId: String? = null - private var body: Body.Builder = Body.builder() - private var additionalHeaders: Headers.Builder = Headers.builder() - private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + @JvmSynthetic internal fun _body(): Body = body - @JvmSynthetic - internal fun from(viewUpdateParams: ViewUpdateParams) = apply { - viewId = viewUpdateParams.viewId - body = viewUpdateParams.body.toBuilder() - additionalHeaders = viewUpdateParams.additionalHeaders.toBuilder() - additionalQueryParams = viewUpdateParams.additionalQueryParams.toBuilder() + fun _pathParam(index: Int): String = + when (index) { + 0 -> viewId + else -> "" } - /** View id */ - fun viewId(viewId: String) = apply { this.viewId = viewId } + override fun _headers(): Headers = additionalHeaders - /** The id of the object the view applies to */ - fun objectId(objectId: String) = apply { body.objectId(objectId) } + override fun _queryParams(): QueryParams = additionalQueryParams - /** - * Sets [Builder.objectId] to an arbitrary JSON value. - * - * You should usually call [Builder.objectId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun objectId(objectId: JsonField) = apply { body.objectId(objectId) } + class Body + private constructor( + private val objectId: JsonField, + private val objectType: JsonField, + private val name: JsonField, + private val options: JsonField, + private val userId: JsonField, + private val viewData: JsonField, + private val viewType: JsonField, + private val additionalProperties: MutableMap, + ) { - /** The object type that the ACL applies to */ - fun objectType(objectType: AclObjectType) = apply { body.objectType(objectType) } + @JsonCreator + private constructor( + @JsonProperty("object_id") + @ExcludeMissing + objectId: JsonField = JsonMissing.of(), + @JsonProperty("object_type") + @ExcludeMissing + objectType: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("options") + @ExcludeMissing + options: JsonField = JsonMissing.of(), + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), + @JsonProperty("view_data") + @ExcludeMissing + viewData: JsonField = JsonMissing.of(), + @JsonProperty("view_type") + @ExcludeMissing + viewType: JsonField = JsonMissing.of(), + ) : this(objectId, objectType, name, options, userId, viewData, viewType, mutableMapOf()) /** - * Sets [Builder.objectType] to an arbitrary JSON value. + * The id of the object the view applies to * - * You should usually call [Builder.objectType] with a well-typed [AclObjectType] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun objectType(objectType: JsonField) = apply { body.objectType(objectType) } - - /** Name of the view */ - fun name(name: String?) = apply { body.name(name) } - - /** Alias for calling [Builder.name] with `name.orElse(null)`. */ - fun name(name: Optional) = name(name.getOrNull()) + fun objectId(): String = objectId.getRequired("object_id") /** - * Sets [Builder.name] to an arbitrary JSON value. + * The object type that the ACL applies to * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun name(name: JsonField) = apply { body.name(name) } + fun objectType(): AclObjectType = objectType.getRequired("object_type") - /** Options for the view in the app */ - fun options(options: ViewOptions?) = apply { body.options(options) } + /** + * Name of the view + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) - /** Alias for calling [Builder.options] with `options.orElse(null)`. */ - fun options(options: Optional) = options(options.getOrNull()) + /** + * Options for the view in the app + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun options(): Optional = Optional.ofNullable(options.getNullable("options")) /** - * Sets [Builder.options] to an arbitrary JSON value. + * Identifies the user who created the view * - * You should usually call [Builder.options] with a well-typed [ViewOptions] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun options(options: JsonField) = apply { body.options(options) } + fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) - /** Identifies the user who created the view */ - fun userId(userId: String?) = apply { body.userId(userId) } + /** + * The view definition + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun viewData(): Optional = Optional.ofNullable(viewData.getNullable("view_data")) - /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ - fun userId(userId: Optional) = userId(userId.getOrNull()) + /** + * Type of table that the view corresponds to. + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun viewType(): Optional = Optional.ofNullable(viewType.getNullable("view_type")) /** - * Sets [Builder.userId] to an arbitrary JSON value. + * Returns the raw JSON value of [objectId]. * - * You should usually call [Builder.userId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [objectId], this method doesn't throw if the JSON field has an unexpected type. */ - fun userId(userId: JsonField) = apply { body.userId(userId) } + @JsonProperty("object_id") @ExcludeMissing fun _objectId(): JsonField = objectId - /** The view definition */ - fun viewData(viewData: ViewData?) = apply { body.viewData(viewData) } + /** + * Returns the raw JSON value of [objectType]. + * + * Unlike [objectType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("object_type") + @ExcludeMissing + fun _objectType(): JsonField = objectType - /** Alias for calling [Builder.viewData] with `viewData.orElse(null)`. */ - fun viewData(viewData: Optional) = viewData(viewData.getOrNull()) + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name /** - * Sets [Builder.viewData] to an arbitrary JSON value. + * Returns the raw JSON value of [options]. * - * You should usually call [Builder.viewData] with a well-typed [ViewData] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [options], this method doesn't throw if the JSON field has an unexpected type. */ - fun viewData(viewData: JsonField) = apply { body.viewData(viewData) } + @JsonProperty("options") @ExcludeMissing fun _options(): JsonField = options - /** Type of table that the view corresponds to. */ - fun viewType(viewType: ViewType?) = apply { body.viewType(viewType) } + /** + * Returns the raw JSON value of [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId - /** Alias for calling [Builder.viewType] with `viewType.orElse(null)`. */ - fun viewType(viewType: Optional) = viewType(viewType.getOrNull()) + /** + * Returns the raw JSON value of [viewData]. + * + * Unlike [viewData], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("view_data") @ExcludeMissing fun _viewData(): JsonField = viewData /** - * Sets [Builder.viewType] to an arbitrary JSON value. + * Returns the raw JSON value of [viewType]. * - * You should usually call [Builder.viewType] with a well-typed [ViewType] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [viewType], this method doesn't throw if the JSON field has an unexpected type. */ - fun viewType(viewType: JsonField) = apply { body.viewType(viewType) } + @JsonProperty("view_type") @ExcludeMissing fun _viewType(): JsonField = viewType - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - body.additionalProperties(additionalBodyProperties) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - body.putAdditionalProperty(key, value) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .objectId() + * .objectType() + * ``` + */ + @JvmStatic fun builder() = Builder() } - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - body.putAllAdditionalProperties(additionalBodyProperties) + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var objectId: JsonField? = null + private var objectType: JsonField? = null + private var name: JsonField = JsonMissing.of() + private var options: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var viewData: JsonField = JsonMissing.of() + private var viewType: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + objectId = body.objectId + objectType = body.objectType + name = body.name + options = body.options + userId = body.userId + viewData = body.viewData + viewType = body.viewType + additionalProperties = body.additionalProperties.toMutableMap() } - fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + /** The id of the object the view applies to */ + fun objectId(objectId: String) = objectId(JsonField.of(objectId)) - fun removeAllAdditionalBodyProperties(keys: Set) = apply { - body.removeAllAdditionalProperties(keys) - } + /** + * Sets [Builder.objectId] to an arbitrary JSON value. + * + * You should usually call [Builder.objectId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun objectId(objectId: JsonField) = apply { this.objectId = objectId } - fun additionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** The object type that the ACL applies to */ + fun objectType(objectType: AclObjectType) = objectType(JsonField.of(objectType)) - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllAdditionalHeaders(additionalHeaders) - } + /** + * Sets [Builder.objectType] to an arbitrary JSON value. + * + * You should usually call [Builder.objectType] with a well-typed [AclObjectType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun objectType(objectType: JsonField) = apply { + this.objectType = objectType + } - fun putAdditionalHeader(name: String, value: String) = apply { - additionalHeaders.put(name, value) - } + /** Name of the view */ + fun name(name: String?) = name(JsonField.ofNullable(name)) - fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.put(name, values) - } + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) - fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } - fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.putAll(additionalHeaders) - } + /** Options for the view in the app */ + fun options(options: ViewOptions?) = options(JsonField.ofNullable(options)) - fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replace(name, value) - } + /** Alias for calling [Builder.options] with `options.orElse(null)`. */ + fun options(options: Optional) = options(options.getOrNull()) - fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replace(name, values) - } + /** + * Sets [Builder.options] to an arbitrary JSON value. + * + * You should usually call [Builder.options] with a well-typed [ViewOptions] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun options(options: JsonField) = apply { this.options = options } - fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** Identifies the user who created the view */ + fun userId(userId: String?) = userId(JsonField.ofNullable(userId)) - fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.replaceAll(additionalHeaders) - } + /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ + fun userId(userId: Optional) = userId(userId.getOrNull()) - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + /** + * Sets [Builder.userId] to an arbitrary JSON value. + * + * You should usually call [Builder.userId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun userId(userId: JsonField) = apply { this.userId = userId } - fun removeAllAdditionalHeaders(names: Set) = apply { - additionalHeaders.removeAll(names) - } + /** The view definition */ + fun viewData(viewData: ViewData?) = viewData(JsonField.ofNullable(viewData)) - fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + /** Alias for calling [Builder.viewData] with `viewData.orElse(null)`. */ + fun viewData(viewData: Optional) = viewData(viewData.getOrNull()) - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllAdditionalQueryParams(additionalQueryParams) - } + /** + * Sets [Builder.viewData] to an arbitrary JSON value. + * + * You should usually call [Builder.viewData] with a well-typed [ViewData] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun viewData(viewData: JsonField) = apply { this.viewData = viewData } - fun putAdditionalQueryParam(key: String, value: String) = apply { - additionalQueryParams.put(key, value) - } + /** Type of table that the view corresponds to. */ + fun viewType(viewType: ViewType?) = viewType(JsonField.ofNullable(viewType)) - fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.put(key, values) - } + /** Alias for calling [Builder.viewType] with `viewType.orElse(null)`. */ + fun viewType(viewType: Optional) = viewType(viewType.getOrNull()) - fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.putAll(additionalQueryParams) - } + /** + * Sets [Builder.viewType] to an arbitrary JSON value. + * + * You should usually call [Builder.viewType] with a well-typed [ViewType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun viewType(viewType: JsonField) = apply { this.viewType = viewType } - fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.putAll(additionalQueryParams) + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) } - fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replace(key, value) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replace(key, values) - } + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } - fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .objectId() + * .objectType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("objectId", objectId), + checkRequired("objectType", objectType), + name, + options, + userId, + viewData, + viewType, + additionalProperties.toMutableMap(), + ) } - fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = - apply { - this.additionalQueryParams.replaceAll(additionalQueryParams) + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply } - fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + objectId() + objectType() + name() + options().ifPresent { it.validate() } + userId() + viewData().ifPresent { it.validate() } + viewType() + validated = true + } - fun removeAllAdditionalQueryParams(keys: Set) = apply { - additionalQueryParams.removeAll(keys) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && objectId == other.objectId && objectType == other.objectType && name == other.name && options == other.options && userId == other.userId && viewData == other.viewData && viewType == other.viewType && additionalProperties == other.additionalProperties /* spotless:on */ } - /** - * Returns an immutable instance of [ViewUpdateParams]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .viewId() - * .objectId() - * .objectType() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ViewUpdateParams = - ViewUpdateParams( - checkRequired("viewId", viewId), - body.build(), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(objectId, objectType, name, options, userId, viewData, viewType, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{objectId=$objectId, objectType=$objectType, name=$name, options=$options, userId=$userId, viewData=$viewData, viewType=$viewType, additionalProperties=$additionalProperties}" } /** Type of table that the view corresponds to. */ diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/SerializerTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/SerializerTest.kt index 824c8711..3fa27790 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/SerializerTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/SerializerTest.kt @@ -11,7 +11,6 @@ import org.junit.jupiter.api.Test internal class SerializerTest { @JsonDeserialize(builder = ClassWithBooleanFieldPrefixedWithIs.Builder::class) - @NoAutoDetect class ClassWithBooleanFieldPrefixedWithIs private constructor( private val isActive: JsonField, @@ -60,7 +59,6 @@ internal class SerializerTest { fun builder() = Builder() } - @NoAutoDetect class Builder internal constructor() { private var isActive: JsonField = JsonMissing.of() From 0ae36b495b2ad5551fe9289f186f5149d5d760b0 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 27 Mar 2025 04:56:54 +0000 Subject: [PATCH 14/42] codegen metadata --- .stats.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.stats.yml b/.stats.yml index 24a7d1d7..5411d578 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,4 @@ configured_endpoints: 110 openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/manugoyal%2Fbraintrust-sdk-f0d64ce0e0efde75f9c171f7f3c3d4a72f00a77abb3bc5a7d65b7be1e715689b.yml +openapi_spec_hash: a027e48cc6aea2fab3cbdd38f4081119 +config_hash: 8b538e7757a50832472e61dd2f54bcfc From 2a52b9fd35ea33391dad9f3e3098e5eb2afcca0d Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 27 Mar 2025 05:20:43 +0000 Subject: [PATCH 15/42] chore(internal): delete unused methods and annotations (#171) fix(client): map deserialization bug --- .../com/braintrustdata/api/models/AISecret.kt | 19 +++-- .../api/models/AclDeleteParams.kt | 21 ++---- .../api/models/AiSecretCreateParams.kt | 19 +++-- .../api/models/AiSecretDeleteParams.kt | 21 ++---- .../api/models/AiSecretReplaceParams.kt | 19 +++-- .../api/models/AiSecretUpdateParams.kt | 19 +++-- .../api/models/ApiKeyDeleteParams.kt | 21 ++---- .../api/models/CrossObjectInsertResponse.kt | 55 ++++++-------- .../com/braintrustdata/api/models/Dataset.kt | 19 +++-- .../api/models/DatasetCreateParams.kt | 19 +++-- .../api/models/DatasetDeleteParams.kt | 21 ++---- .../api/models/DatasetUpdateParams.kt | 19 +++-- .../api/models/EnvVarDeleteParams.kt | 21 ++---- .../api/models/EvalCreateParams.kt | 72 ++++++++----------- .../braintrustdata/api/models/Experiment.kt | 19 +++-- .../api/models/ExperimentCreateParams.kt | 19 +++-- .../api/models/ExperimentDeleteParams.kt | 21 ++---- .../api/models/ExperimentEvent.kt | 18 ++--- .../api/models/ExperimentUpdateParams.kt | 19 +++-- .../api/models/FeedbackDatasetItem.kt | 18 ++--- .../api/models/FeedbackExperimentItem.kt | 36 ++++------ .../api/models/FeedbackProjectLogsItem.kt | 36 ++++------ .../com/braintrustdata/api/models/Function.kt | 18 ++--- .../api/models/FunctionDeleteParams.kt | 21 ++---- .../api/models/FunctionInvokeParams.kt | 36 ++++------ .../api/models/GroupDeleteParams.kt | 21 ++---- .../api/models/InsertExperimentEvent.kt | 18 ++--- .../api/models/InsertProjectLogsEvent.kt | 18 ++--- .../api/models/OrganizationDeleteParams.kt | 21 ++---- .../api/models/ProjectDeleteParams.kt | 21 ++---- .../api/models/ProjectLogsEvent.kt | 18 ++--- .../braintrustdata/api/models/ProjectScore.kt | 19 +++-- .../api/models/ProjectScoreCreateParams.kt | 19 +++-- .../api/models/ProjectScoreDeleteParams.kt | 21 ++---- .../api/models/ProjectScoreReplaceParams.kt | 19 +++-- .../api/models/ProjectScoreUpdateParams.kt | 19 +++-- .../api/models/ProjectTagDeleteParams.kt | 21 ++---- .../com/braintrustdata/api/models/Prompt.kt | 18 ++--- .../braintrustdata/api/models/PromptData.kt | 18 ++--- .../api/models/PromptDeleteParams.kt | 21 ++---- .../api/models/PromptOptions.kt | 16 ++--- .../api/models/RoleDeleteParams.kt | 21 ++---- .../api/models/SpanIframeDeleteParams.kt | 21 ++---- .../api/models/SummarizeExperimentResponse.kt | 37 ++++------ .../braintrustdata/api/models/ViewOptions.kt | 36 ++++------ 45 files changed, 369 insertions(+), 680 deletions(-) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AISecret.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AISecret.kt index 364b5190..40528d3e 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AISecret.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AISecret.kt @@ -7,6 +7,7 @@ import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -396,19 +397,15 @@ private constructor( } class Metadata - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -452,7 +449,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclDeleteParams.kt index 5a35222f..03f89bcb 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclDeleteParams.kt @@ -2,15 +2,12 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import java.util.Collections +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional @@ -20,26 +17,18 @@ private constructor( private val aclId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: MutableMap, + private val additionalBodyProperties: Map, ) : Params { /** Acl id */ fun aclId(): String = aclId + fun _additionalBodyProperties(): Map = additionalBodyProperties + fun _additionalHeaders(): Headers = additionalHeaders fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JsonAnySetter - private fun putAdditionalBodyProperty(key: String, value: JsonValue) { - additionalBodyProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalBodyProperties(): Map = - Collections.unmodifiableMap(additionalBodyProperties) - fun toBuilder() = Builder().from(this) companion object { @@ -211,7 +200,7 @@ private constructor( checkRequired("aclId", aclId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toMutableMap(), + additionalBodyProperties.toImmutable(), ) } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt index bb2aafb0..4b1c5c19 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt @@ -10,6 +10,7 @@ import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -649,19 +650,15 @@ private constructor( } class Metadata - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -705,7 +702,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretDeleteParams.kt index 53f7336b..903f3bf0 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretDeleteParams.kt @@ -2,15 +2,12 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import java.util.Collections +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional @@ -20,26 +17,18 @@ private constructor( private val aiSecretId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: MutableMap, + private val additionalBodyProperties: Map, ) : Params { /** AiSecret id */ fun aiSecretId(): String = aiSecretId + fun _additionalBodyProperties(): Map = additionalBodyProperties + fun _additionalHeaders(): Headers = additionalHeaders fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JsonAnySetter - private fun putAdditionalBodyProperty(key: String, value: JsonValue) { - additionalBodyProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalBodyProperties(): Map = - Collections.unmodifiableMap(additionalBodyProperties) - fun toBuilder() = Builder().from(this) companion object { @@ -211,7 +200,7 @@ private constructor( checkRequired("aiSecretId", aiSecretId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toMutableMap(), + additionalBodyProperties.toImmutable(), ) } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt index 649fd2a8..6332eda2 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt @@ -10,6 +10,7 @@ import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -649,19 +650,15 @@ private constructor( } class Metadata - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -705,7 +702,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt index 6b47818b..861e0147 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt @@ -10,6 +10,7 @@ import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -561,19 +562,15 @@ private constructor( } class Metadata - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -617,7 +614,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParams.kt index ba7d278a..b0521f29 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParams.kt @@ -2,15 +2,12 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import java.util.Collections +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional @@ -20,26 +17,18 @@ private constructor( private val apiKeyId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: MutableMap, + private val additionalBodyProperties: Map, ) : Params { /** ApiKey id */ fun apiKeyId(): String = apiKeyId + fun _additionalBodyProperties(): Map = additionalBodyProperties + fun _additionalHeaders(): Headers = additionalHeaders fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JsonAnySetter - private fun putAdditionalBodyProperty(key: String, value: JsonValue) { - additionalBodyProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalBodyProperties(): Map = - Collections.unmodifiableMap(additionalBodyProperties) - fun toBuilder() = Builder().from(this) companion object { @@ -211,7 +200,7 @@ private constructor( checkRequired("apiKeyId", apiKeyId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toMutableMap(), + additionalBodyProperties.toImmutable(), ) } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponse.kt index 2b8708db..bd424e7a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponse.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -216,19 +217,15 @@ private constructor( /** A mapping from dataset id to row ids for inserted `events` */ class Dataset - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -272,7 +269,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Dataset = Dataset(additionalProperties.toMutableMap()) + fun build(): Dataset = Dataset(additionalProperties.toImmutable()) } private var validated: Boolean = false @@ -304,19 +301,15 @@ private constructor( /** A mapping from experiment id to row ids for inserted `events` */ class Experiment - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -360,7 +353,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Experiment = Experiment(additionalProperties.toMutableMap()) + fun build(): Experiment = Experiment(additionalProperties.toImmutable()) } private var validated: Boolean = false @@ -392,19 +385,15 @@ private constructor( /** A mapping from project id to row ids for inserted `events` */ class ProjectLogs - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -448,7 +437,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): ProjectLogs = ProjectLogs(additionalProperties.toMutableMap()) + fun build(): ProjectLogs = ProjectLogs(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Dataset.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Dataset.kt index 518909cf..4eb764fc 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Dataset.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Dataset.kt @@ -7,6 +7,7 @@ import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -401,19 +402,15 @@ private constructor( /** User-controlled metadata about the dataset */ class Metadata - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -457,7 +454,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt index 01d2dbd5..8000d930 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt @@ -10,6 +10,7 @@ import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -586,19 +587,15 @@ private constructor( /** User-controlled metadata about the dataset */ class Metadata - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -642,7 +639,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetDeleteParams.kt index c7a03bab..ffc87279 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetDeleteParams.kt @@ -2,15 +2,12 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import java.util.Collections +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional @@ -20,26 +17,18 @@ private constructor( private val datasetId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: MutableMap, + private val additionalBodyProperties: Map, ) : Params { /** Dataset id */ fun datasetId(): String = datasetId + fun _additionalBodyProperties(): Map = additionalBodyProperties + fun _additionalHeaders(): Headers = additionalHeaders fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JsonAnySetter - private fun putAdditionalBodyProperty(key: String, value: JsonValue) { - additionalBodyProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalBodyProperties(): Map = - Collections.unmodifiableMap(additionalBodyProperties) - fun toBuilder() = Builder().from(this) companion object { @@ -211,7 +200,7 @@ private constructor( checkRequired("datasetId", datasetId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toMutableMap(), + additionalBodyProperties.toImmutable(), ) } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt index c605eabf..036b54b7 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt @@ -10,6 +10,7 @@ import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -524,19 +525,15 @@ private constructor( /** User-controlled metadata about the dataset */ class Metadata - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -580,7 +577,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarDeleteParams.kt index 2db92a78..8196496d 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarDeleteParams.kt @@ -2,15 +2,12 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import java.util.Collections +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional @@ -20,26 +17,18 @@ private constructor( private val envVarId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: MutableMap, + private val additionalBodyProperties: Map, ) : Params { /** EnvVar id */ fun envVarId(): String = envVarId + fun _additionalBodyProperties(): Map = additionalBodyProperties + fun _additionalHeaders(): Headers = additionalHeaders fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JsonAnySetter - private fun putAdditionalBodyProperty(key: String, value: JsonValue) { - additionalBodyProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalBodyProperties(): Map = - Collections.unmodifiableMap(additionalBodyProperties) - fun toBuilder() = Builder().from(this) companion object { @@ -211,7 +200,7 @@ private constructor( checkRequired("envVarId", envVarId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toMutableMap(), + additionalBodyProperties.toImmutable(), ) } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt index 9ce4d6a0..d8be175f 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt @@ -2082,19 +2082,15 @@ private constructor( } class _InternalBtql - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -2143,7 +2139,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): _InternalBtql = _InternalBtql(additionalProperties.toMutableMap()) + fun build(): _InternalBtql = _InternalBtql(additionalProperties.toImmutable()) } private var validated: Boolean = false @@ -2409,19 +2405,15 @@ private constructor( } class _InternalBtql - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -2470,7 +2462,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): _InternalBtql = _InternalBtql(additionalProperties.toMutableMap()) + fun build(): _InternalBtql = _InternalBtql(additionalProperties.toImmutable()) } private var validated: Boolean = false @@ -6665,19 +6657,15 @@ private constructor( * slice & dice across experiments. */ class Metadata - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -6721,7 +6709,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) } private var validated: Boolean = false @@ -7263,19 +7251,15 @@ private constructor( /** Include these properties in every span created under this parent */ class PropagatedEvent - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -7325,7 +7309,7 @@ private constructor( * Further updates to this [Builder] will not mutate the returned instance. */ fun build(): PropagatedEvent = - PropagatedEvent(additionalProperties.toMutableMap()) + PropagatedEvent(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Experiment.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Experiment.kt index c7edbb88..f381c0db 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Experiment.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Experiment.kt @@ -7,6 +7,7 @@ import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -651,19 +652,15 @@ private constructor( /** User-controlled metadata about the experiment */ class Metadata - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -707,7 +704,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentCreateParams.kt index 32189c2d..a222a370 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentCreateParams.kt @@ -10,6 +10,7 @@ import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -1079,19 +1080,15 @@ private constructor( /** User-controlled metadata about the experiment */ class Metadata - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -1135,7 +1132,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentDeleteParams.kt index c71f8065..6b8f8458 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentDeleteParams.kt @@ -2,15 +2,12 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import java.util.Collections +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional @@ -20,26 +17,18 @@ private constructor( private val experimentId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: MutableMap, + private val additionalBodyProperties: Map, ) : Params { /** Experiment id */ fun experimentId(): String = experimentId + fun _additionalBodyProperties(): Map = additionalBodyProperties + fun _additionalHeaders(): Headers = additionalHeaders fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JsonAnySetter - private fun putAdditionalBodyProperty(key: String, value: JsonValue) { - additionalBodyProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalBodyProperties(): Map = - Collections.unmodifiableMap(additionalBodyProperties) - fun toBuilder() = Builder().from(this) companion object { @@ -212,7 +201,7 @@ private constructor( checkRequired("experimentId", experimentId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toMutableMap(), + additionalBodyProperties.toImmutable(), ) } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentEvent.kt index beb9b9aa..a8da82d9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentEvent.kt @@ -1686,19 +1686,15 @@ private constructor( * help you sort, filter, and compare experiments */ class Scores - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -1742,7 +1738,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Scores = Scores(additionalProperties.toMutableMap()) + fun build(): Scores = Scores(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt index fda66de1..a0bf9a1e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt @@ -10,6 +10,7 @@ import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -923,19 +924,15 @@ private constructor( /** User-controlled metadata about the experiment */ class Metadata - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -979,7 +976,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackDatasetItem.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackDatasetItem.kt index 291901e8..a5dea86c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackDatasetItem.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackDatasetItem.kt @@ -312,19 +312,15 @@ private constructor( * event itself, but rather the audit log attached to the event. */ class Metadata - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -368,7 +364,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackExperimentItem.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackExperimentItem.kt index cd33c855..193b9801 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackExperimentItem.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackExperimentItem.kt @@ -368,19 +368,15 @@ private constructor( * event itself, but rather the audit log attached to the event. */ class Metadata - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -424,7 +420,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) } private var validated: Boolean = false @@ -459,19 +455,15 @@ private constructor( * existing scores for the experiment event */ class Scores - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -515,7 +507,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Scores = Scores(additionalProperties.toMutableMap()) + fun build(): Scores = Scores(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItem.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItem.kt index 5ce7211e..875f4110 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItem.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItem.kt @@ -368,19 +368,15 @@ private constructor( * event itself, but rather the audit log attached to the event. */ class Metadata - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -424,7 +420,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) } private var validated: Boolean = false @@ -459,19 +455,15 @@ private constructor( * existing scores for the project logs event */ class Scores - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -515,7 +507,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Scores = Scores(additionalProperties.toMutableMap()) + fun build(): Scores = Scores(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Function.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Function.kt index 105b24aa..d2ca2dab 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Function.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Function.kt @@ -3225,19 +3225,15 @@ private constructor( /** User-controlled metadata about the prompt */ class Metadata - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -3281,7 +3277,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionDeleteParams.kt index c2e2e81c..0e216910 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionDeleteParams.kt @@ -2,15 +2,12 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import java.util.Collections +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional @@ -20,26 +17,18 @@ private constructor( private val functionId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: MutableMap, + private val additionalBodyProperties: Map, ) : Params { /** Function id */ fun functionId(): String = functionId + fun _additionalBodyProperties(): Map = additionalBodyProperties + fun _additionalHeaders(): Headers = additionalHeaders fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JsonAnySetter - private fun putAdditionalBodyProperty(key: String, value: JsonValue) { - additionalBodyProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalBodyProperties(): Map = - Collections.unmodifiableMap(additionalBodyProperties) - fun toBuilder() = Builder().from(this) companion object { @@ -211,7 +200,7 @@ private constructor( checkRequired("functionId", functionId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toMutableMap(), + additionalBodyProperties.toImmutable(), ) } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt index 439596d8..86f08250 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt @@ -3453,19 +3453,15 @@ private constructor( /** Any relevant metadata */ class Metadata - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -3509,7 +3505,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) } private var validated: Boolean = false @@ -4152,19 +4148,15 @@ private constructor( /** Include these properties in every span created under this parent */ class PropagatedEvent - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -4214,7 +4206,7 @@ private constructor( * Further updates to this [Builder] will not mutate the returned instance. */ fun build(): PropagatedEvent = - PropagatedEvent(additionalProperties.toMutableMap()) + PropagatedEvent(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupDeleteParams.kt index 7bc274cc..20966178 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupDeleteParams.kt @@ -2,15 +2,12 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import java.util.Collections +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional @@ -20,26 +17,18 @@ private constructor( private val groupId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: MutableMap, + private val additionalBodyProperties: Map, ) : Params { /** Group id */ fun groupId(): String = groupId + fun _additionalBodyProperties(): Map = additionalBodyProperties + fun _additionalHeaders(): Headers = additionalHeaders fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JsonAnySetter - private fun putAdditionalBodyProperty(key: String, value: JsonValue) { - additionalBodyProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalBodyProperties(): Map = - Collections.unmodifiableMap(additionalBodyProperties) - fun toBuilder() = Builder().from(this) companion object { @@ -211,7 +200,7 @@ private constructor( checkRequired("groupId", groupId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toMutableMap(), + additionalBodyProperties.toImmutable(), ) } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertExperimentEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertExperimentEvent.kt index d4cc1375..e335fd4c 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertExperimentEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertExperimentEvent.kt @@ -1863,19 +1863,15 @@ private constructor( * help you sort, filter, and compare experiments */ class Scores - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -1919,7 +1915,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Scores = Scores(additionalProperties.toMutableMap()) + fun build(): Scores = Scores(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertProjectLogsEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertProjectLogsEvent.kt index 1c4d1702..c2e77ee5 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertProjectLogsEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertProjectLogsEvent.kt @@ -1855,19 +1855,15 @@ private constructor( * help you sort, filter, and compare logs. */ class Scores - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -1911,7 +1907,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Scores = Scores(additionalProperties.toMutableMap()) + fun build(): Scores = Scores(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationDeleteParams.kt index eaaf6ad0..336c55bb 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationDeleteParams.kt @@ -2,15 +2,12 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import java.util.Collections +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional @@ -20,26 +17,18 @@ private constructor( private val organizationId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: MutableMap, + private val additionalBodyProperties: Map, ) : Params { /** Organization id */ fun organizationId(): String = organizationId + fun _additionalBodyProperties(): Map = additionalBodyProperties + fun _additionalHeaders(): Headers = additionalHeaders fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JsonAnySetter - private fun putAdditionalBodyProperty(key: String, value: JsonValue) { - additionalBodyProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalBodyProperties(): Map = - Collections.unmodifiableMap(additionalBodyProperties) - fun toBuilder() = Builder().from(this) companion object { @@ -212,7 +201,7 @@ private constructor( checkRequired("organizationId", organizationId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toMutableMap(), + additionalBodyProperties.toImmutable(), ) } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectDeleteParams.kt index 7b46451b..e753af7e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectDeleteParams.kt @@ -2,15 +2,12 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import java.util.Collections +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional @@ -20,26 +17,18 @@ private constructor( private val projectId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: MutableMap, + private val additionalBodyProperties: Map, ) : Params { /** Project id */ fun projectId(): String = projectId + fun _additionalBodyProperties(): Map = additionalBodyProperties + fun _additionalHeaders(): Headers = additionalHeaders fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JsonAnySetter - private fun putAdditionalBodyProperty(key: String, value: JsonValue) { - additionalBodyProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalBodyProperties(): Map = - Collections.unmodifiableMap(additionalBodyProperties) - fun toBuilder() = Builder().from(this) companion object { @@ -211,7 +200,7 @@ private constructor( checkRequired("projectId", projectId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toMutableMap(), + additionalBodyProperties.toImmutable(), ) } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogsEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogsEvent.kt index f76bd22d..5d406343 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogsEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogsEvent.kt @@ -1803,19 +1803,15 @@ private constructor( * help you sort, filter, and compare logs. */ class Scores - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -1859,7 +1855,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Scores = Scores(additionalProperties.toMutableMap()) + fun build(): Scores = Scores(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScore.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScore.kt index 0a4d877a..41a42006 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScore.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScore.kt @@ -10,6 +10,7 @@ import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow +import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -674,19 +675,15 @@ private constructor( /** For weighted-type project scores, the weights of each score */ class Weighted - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -733,7 +730,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Weighted = Weighted(additionalProperties.toMutableMap()) + fun build(): Weighted = Weighted(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParams.kt index 64a558f5..f626e896 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParams.kt @@ -13,6 +13,7 @@ import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -931,19 +932,15 @@ private constructor( /** For weighted-type project scores, the weights of each score */ class Weighted - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -990,7 +987,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Weighted = Weighted(additionalProperties.toMutableMap()) + fun build(): Weighted = Weighted(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreDeleteParams.kt index 4150f67f..b9f17660 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreDeleteParams.kt @@ -2,15 +2,12 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import java.util.Collections +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional @@ -20,26 +17,18 @@ private constructor( private val projectScoreId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: MutableMap, + private val additionalBodyProperties: Map, ) : Params { /** ProjectScore id */ fun projectScoreId(): String = projectScoreId + fun _additionalBodyProperties(): Map = additionalBodyProperties + fun _additionalHeaders(): Headers = additionalHeaders fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JsonAnySetter - private fun putAdditionalBodyProperty(key: String, value: JsonValue) { - additionalBodyProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalBodyProperties(): Map = - Collections.unmodifiableMap(additionalBodyProperties) - fun toBuilder() = Builder().from(this) companion object { @@ -212,7 +201,7 @@ private constructor( checkRequired("projectScoreId", projectScoreId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toMutableMap(), + additionalBodyProperties.toImmutable(), ) } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParams.kt index e5d8d410..acfc9aa7 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParams.kt @@ -13,6 +13,7 @@ import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -932,19 +933,15 @@ private constructor( /** For weighted-type project scores, the weights of each score */ class Weighted - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -991,7 +988,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Weighted = Weighted(additionalProperties.toMutableMap()) + fun build(): Weighted = Weighted(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt index 49e05343..a23ead97 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt @@ -13,6 +13,7 @@ import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -877,19 +878,15 @@ private constructor( /** For weighted-type project scores, the weights of each score */ class Weighted - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -936,7 +933,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Weighted = Weighted(additionalProperties.toMutableMap()) + fun build(): Weighted = Weighted(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagDeleteParams.kt index b3d6122f..94f3669c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagDeleteParams.kt @@ -2,15 +2,12 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import java.util.Collections +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional @@ -20,26 +17,18 @@ private constructor( private val projectTagId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: MutableMap, + private val additionalBodyProperties: Map, ) : Params { /** ProjectTag id */ fun projectTagId(): String = projectTagId + fun _additionalBodyProperties(): Map = additionalBodyProperties + fun _additionalHeaders(): Headers = additionalHeaders fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JsonAnySetter - private fun putAdditionalBodyProperty(key: String, value: JsonValue) { - additionalBodyProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalBodyProperties(): Map = - Collections.unmodifiableMap(additionalBodyProperties) - fun toBuilder() = Builder().from(this) companion object { @@ -212,7 +201,7 @@ private constructor( checkRequired("projectTagId", projectTagId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toMutableMap(), + additionalBodyProperties.toImmutable(), ) } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Prompt.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Prompt.kt index 9adc2473..1c81b37b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Prompt.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Prompt.kt @@ -825,19 +825,15 @@ private constructor( /** User-controlled metadata about the prompt */ class Metadata - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -881,7 +877,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metadata = Metadata(additionalProperties.toMutableMap()) + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptData.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptData.kt index 844aa180..7fc43fbc 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptData.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptData.kt @@ -692,19 +692,15 @@ private constructor( } class ChoiceScores - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -751,7 +747,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): ChoiceScores = ChoiceScores(additionalProperties.toMutableMap()) + fun build(): ChoiceScores = ChoiceScores(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptDeleteParams.kt index d4ae1f6b..81512eeb 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptDeleteParams.kt @@ -2,15 +2,12 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import java.util.Collections +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional @@ -20,26 +17,18 @@ private constructor( private val promptId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: MutableMap, + private val additionalBodyProperties: Map, ) : Params { /** Prompt id */ fun promptId(): String = promptId + fun _additionalBodyProperties(): Map = additionalBodyProperties + fun _additionalHeaders(): Headers = additionalHeaders fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JsonAnySetter - private fun putAdditionalBodyProperty(key: String, value: JsonValue) { - additionalBodyProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalBodyProperties(): Map = - Collections.unmodifiableMap(additionalBodyProperties) - fun toBuilder() = Builder().from(this) companion object { @@ -211,7 +200,7 @@ private constructor( checkRequired("promptId", promptId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toMutableMap(), + additionalBodyProperties.toImmutable(), ) } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptOptions.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptOptions.kt index 6d100afe..d060274a 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptOptions.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptOptions.kt @@ -2535,21 +2535,16 @@ private constructor( } class Object + @JsonCreator private constructor( - private val additionalProperties: MutableMap + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map ) { - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + additionalProperties fun toBuilder() = Builder().from(this) @@ -2607,8 +2602,7 @@ private constructor( * Further updates to this [Builder] will not mutate the * returned instance. */ - fun build(): Object = - Object(additionalProperties.toMutableMap()) + fun build(): Object = Object(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleDeleteParams.kt index 4c6028d6..039de039 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleDeleteParams.kt @@ -2,15 +2,12 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import java.util.Collections +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional @@ -20,26 +17,18 @@ private constructor( private val roleId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: MutableMap, + private val additionalBodyProperties: Map, ) : Params { /** Role id */ fun roleId(): String = roleId + fun _additionalBodyProperties(): Map = additionalBodyProperties + fun _additionalHeaders(): Headers = additionalHeaders fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JsonAnySetter - private fun putAdditionalBodyProperty(key: String, value: JsonValue) { - additionalBodyProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalBodyProperties(): Map = - Collections.unmodifiableMap(additionalBodyProperties) - fun toBuilder() = Builder().from(this) companion object { @@ -211,7 +200,7 @@ private constructor( checkRequired("roleId", roleId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toMutableMap(), + additionalBodyProperties.toImmutable(), ) } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeDeleteParams.kt index be2af662..c62ab604 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeDeleteParams.kt @@ -2,15 +2,12 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import java.util.Collections +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional @@ -20,26 +17,18 @@ private constructor( private val spanIframeId: String, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: MutableMap, + private val additionalBodyProperties: Map, ) : Params { /** SpanIframe id */ fun spanIframeId(): String = spanIframeId + fun _additionalBodyProperties(): Map = additionalBodyProperties + fun _additionalHeaders(): Headers = additionalHeaders fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JsonAnySetter - private fun putAdditionalBodyProperty(key: String, value: JsonValue) { - additionalBodyProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalBodyProperties(): Map = - Collections.unmodifiableMap(additionalBodyProperties) - fun toBuilder() = Builder().from(this) companion object { @@ -212,7 +201,7 @@ private constructor( checkRequired("spanIframeId", spanIframeId), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toMutableMap(), + additionalBodyProperties.toImmutable(), ) } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SummarizeExperimentResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SummarizeExperimentResponse.kt index 1158c9d9..ed4989dc 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SummarizeExperimentResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SummarizeExperimentResponse.kt @@ -7,6 +7,7 @@ import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.toImmutable import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -395,19 +396,15 @@ private constructor( /** Summary of the experiment's metrics */ class Metrics - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -451,7 +448,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Metrics = Metrics(additionalProperties.toMutableMap()) + fun build(): Metrics = Metrics(additionalProperties.toImmutable()) } private var validated: Boolean = false @@ -483,19 +480,15 @@ private constructor( /** Summary of the experiment's scores */ class Scores - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -539,7 +532,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Scores = Scores(additionalProperties.toMutableMap()) + fun build(): Scores = Scores(additionalProperties.toImmutable()) } private var validated: Boolean = false diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewOptions.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewOptions.kt index 14f15eb4..000a9ce4 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewOptions.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewOptions.kt @@ -339,19 +339,15 @@ private constructor( } class ColumnSizing - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -395,7 +391,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): ColumnSizing = ColumnSizing(additionalProperties.toMutableMap()) + fun build(): ColumnSizing = ColumnSizing(additionalProperties.toImmutable()) } private var validated: Boolean = false @@ -426,19 +422,15 @@ private constructor( } class ColumnVisibility - private constructor(private val additionalProperties: MutableMap) { - - @JsonCreator private constructor() : this(mutableMapOf()) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun _additionalProperties(): Map = additionalProperties fun toBuilder() = Builder().from(this) @@ -482,7 +474,7 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): ColumnVisibility = ColumnVisibility(additionalProperties.toMutableMap()) + fun build(): ColumnVisibility = ColumnVisibility(additionalProperties.toImmutable()) } private var validated: Boolean = false From d15ef50ea2a826653c7b2ddebabefadc60b1864d Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 28 Mar 2025 05:19:04 +0000 Subject: [PATCH 16/42] chore(internal): swap from `Builder().from(...)` to `toBuilder()` (#172) --- .../com/braintrustdata/api/models/AclListPage.kt | 8 ++------ .../braintrustdata/api/models/AclListPageAsync.kt | 8 ++------ .../braintrustdata/api/models/AiSecretListPage.kt | 14 ++------------ .../api/models/AiSecretListPageAsync.kt | 14 ++------------ .../braintrustdata/api/models/ApiKeyListPage.kt | 8 ++------ .../api/models/ApiKeyListPageAsync.kt | 8 ++------ .../braintrustdata/api/models/DatasetListPage.kt | 14 ++------------ .../api/models/DatasetListPageAsync.kt | 14 ++------------ .../api/models/ExperimentListPage.kt | 14 ++------------ .../api/models/ExperimentListPageAsync.kt | 14 ++------------ .../braintrustdata/api/models/FunctionListPage.kt | 14 ++------------ .../api/models/FunctionListPageAsync.kt | 14 ++------------ .../com/braintrustdata/api/models/GroupListPage.kt | 8 ++------ .../api/models/GroupListPageAsync.kt | 8 ++------ .../api/models/OrganizationListPage.kt | 14 ++------------ .../api/models/OrganizationListPageAsync.kt | 14 ++------------ .../braintrustdata/api/models/ProjectListPage.kt | 14 ++------------ .../api/models/ProjectListPageAsync.kt | 14 ++------------ .../api/models/ProjectScoreListPage.kt | 14 ++------------ .../api/models/ProjectScoreListPageAsync.kt | 14 ++------------ .../api/models/ProjectTagListPage.kt | 14 ++------------ .../api/models/ProjectTagListPageAsync.kt | 14 ++------------ .../braintrustdata/api/models/PromptListPage.kt | 8 ++------ .../api/models/PromptListPageAsync.kt | 8 ++------ .../com/braintrustdata/api/models/RoleListPage.kt | 8 ++------ .../braintrustdata/api/models/RoleListPageAsync.kt | 8 ++------ .../api/models/SpanIframeListPage.kt | 14 ++------------ .../api/models/SpanIframeListPageAsync.kt | 14 ++------------ .../com/braintrustdata/api/models/UserListPage.kt | 8 ++------ .../braintrustdata/api/models/UserListPageAsync.kt | 8 ++------ .../com/braintrustdata/api/models/ViewListPage.kt | 8 ++------ .../braintrustdata/api/models/ViewListPageAsync.kt | 8 ++------ 32 files changed, 64 insertions(+), 300 deletions(-) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt index b4f391b2..98928291 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt @@ -56,13 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - AclListParams.builder().from(params).endingBefore(objects().first().id()).build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - AclListParams.builder().from(params).startingAfter(objects().last().id()).build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt index 52002368..0e59859a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt @@ -56,13 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - AclListParams.builder().from(params).endingBefore(objects().first().id()).build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - AclListParams.builder().from(params).startingAfter(objects().last().id()).build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt index 67a0e6dc..c3c09ba0 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt @@ -56,19 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - AiSecretListParams.builder() - .from(params) - .endingBefore(objects().first().id()) - .build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - AiSecretListParams.builder() - .from(params) - .startingAfter(objects().last().id()) - .build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt index add111f4..861ba05f 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt @@ -56,19 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - AiSecretListParams.builder() - .from(params) - .endingBefore(objects().first().id()) - .build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - AiSecretListParams.builder() - .from(params) - .startingAfter(objects().last().id()) - .build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt index d5c56dc4..b12a7e29 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt @@ -56,13 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - ApiKeyListParams.builder().from(params).endingBefore(objects().first().id()).build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - ApiKeyListParams.builder().from(params).startingAfter(objects().last().id()).build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt index 744c3853..2a40c262 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt @@ -56,13 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - ApiKeyListParams.builder().from(params).endingBefore(objects().first().id()).build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - ApiKeyListParams.builder().from(params).startingAfter(objects().last().id()).build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt index 55ab6c83..aebf0e48 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt @@ -56,19 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - DatasetListParams.builder() - .from(params) - .endingBefore(objects().first().id()) - .build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - DatasetListParams.builder() - .from(params) - .startingAfter(objects().last().id()) - .build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt index 58f04b63..a23154ba 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt @@ -56,19 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - DatasetListParams.builder() - .from(params) - .endingBefore(objects().first().id()) - .build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - DatasetListParams.builder() - .from(params) - .startingAfter(objects().last().id()) - .build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt index 26da97c0..8de7238f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt @@ -56,19 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - ExperimentListParams.builder() - .from(params) - .endingBefore(objects().first().id()) - .build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - ExperimentListParams.builder() - .from(params) - .startingAfter(objects().last().id()) - .build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt index 5502e0e2..9cdda223 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt @@ -56,19 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - ExperimentListParams.builder() - .from(params) - .endingBefore(objects().first().id()) - .build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - ExperimentListParams.builder() - .from(params) - .startingAfter(objects().last().id()) - .build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPage.kt index 98c86b49..7f515922 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPage.kt @@ -56,19 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - FunctionListParams.builder() - .from(params) - .endingBefore(objects().first().id()) - .build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - FunctionListParams.builder() - .from(params) - .startingAfter(objects().last().id()) - .build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageAsync.kt index 46945c42..0ef0f22f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageAsync.kt @@ -56,19 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - FunctionListParams.builder() - .from(params) - .endingBefore(objects().first().id()) - .build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - FunctionListParams.builder() - .from(params) - .startingAfter(objects().last().id()) - .build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt index 4d64e639..bf5f8743 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt @@ -56,13 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - GroupListParams.builder().from(params).endingBefore(objects().first().id()).build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - GroupListParams.builder().from(params).startingAfter(objects().last().id()).build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt index 59586a2c..8ddc2ba7 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt @@ -56,13 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - GroupListParams.builder().from(params).endingBefore(objects().first().id()).build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - GroupListParams.builder().from(params).startingAfter(objects().last().id()).build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt index 9d935959..f2c435ae 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt @@ -56,19 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - OrganizationListParams.builder() - .from(params) - .endingBefore(objects().first().id()) - .build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - OrganizationListParams.builder() - .from(params) - .startingAfter(objects().last().id()) - .build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt index 7823eb8e..a73956de 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt @@ -56,19 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - OrganizationListParams.builder() - .from(params) - .endingBefore(objects().first().id()) - .build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - OrganizationListParams.builder() - .from(params) - .startingAfter(objects().last().id()) - .build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPage.kt index 2fe8b5d0..f7ff4945 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPage.kt @@ -56,19 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - ProjectListParams.builder() - .from(params) - .endingBefore(objects().first().id()) - .build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - ProjectListParams.builder() - .from(params) - .startingAfter(objects().last().id()) - .build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageAsync.kt index 07c848e1..15af7bb1 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageAsync.kt @@ -56,19 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - ProjectListParams.builder() - .from(params) - .endingBefore(objects().first().id()) - .build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - ProjectListParams.builder() - .from(params) - .startingAfter(objects().last().id()) - .build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt index c997e41d..aee346bb 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt @@ -56,19 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - ProjectScoreListParams.builder() - .from(params) - .endingBefore(objects().first().id()) - .build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - ProjectScoreListParams.builder() - .from(params) - .startingAfter(objects().last().id()) - .build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt index 1109ba6c..24fb91c8 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt @@ -56,19 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - ProjectScoreListParams.builder() - .from(params) - .endingBefore(objects().first().id()) - .build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - ProjectScoreListParams.builder() - .from(params) - .startingAfter(objects().last().id()) - .build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt index a6be57ba..d388029f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt @@ -56,19 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - ProjectTagListParams.builder() - .from(params) - .endingBefore(objects().first().id()) - .build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - ProjectTagListParams.builder() - .from(params) - .startingAfter(objects().last().id()) - .build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt index 43492662..9cbb6eca 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt @@ -56,19 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - ProjectTagListParams.builder() - .from(params) - .endingBefore(objects().first().id()) - .build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - ProjectTagListParams.builder() - .from(params) - .startingAfter(objects().last().id()) - .build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt index 86a417c9..fb903078 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt @@ -56,13 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - PromptListParams.builder().from(params).endingBefore(objects().first().id()).build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - PromptListParams.builder().from(params).startingAfter(objects().last().id()).build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt index 3be8e4a9..bb3ee459 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt @@ -56,13 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - PromptListParams.builder().from(params).endingBefore(objects().first().id()).build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - PromptListParams.builder().from(params).startingAfter(objects().last().id()).build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt index 084bdcb4..aeb09d72 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt @@ -56,13 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - RoleListParams.builder().from(params).endingBefore(objects().first().id()).build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - RoleListParams.builder().from(params).startingAfter(objects().last().id()).build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt index 76e6b11d..b75ec089 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt @@ -56,13 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - RoleListParams.builder().from(params).endingBefore(objects().first().id()).build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - RoleListParams.builder().from(params).startingAfter(objects().last().id()).build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt index b7e074d8..56719e29 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt @@ -56,19 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - SpanIframeListParams.builder() - .from(params) - .endingBefore(objects().first().id()) - .build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - SpanIframeListParams.builder() - .from(params) - .startingAfter(objects().last().id()) - .build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt index 8c067706..3ff61ee7 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt @@ -56,19 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - SpanIframeListParams.builder() - .from(params) - .endingBefore(objects().first().id()) - .build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - SpanIframeListParams.builder() - .from(params) - .startingAfter(objects().last().id()) - .build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt index 8afb6f9d..e2a4b2d7 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt @@ -56,13 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - UserListParams.builder().from(params).endingBefore(objects().first().id()).build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - UserListParams.builder().from(params).startingAfter(objects().last().id()).build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt index b5424cfd..4942040a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt @@ -56,13 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - UserListParams.builder().from(params).endingBefore(objects().first().id()).build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - UserListParams.builder().from(params).startingAfter(objects().last().id()).build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt index 371fc6e7..782eae28 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt @@ -56,13 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - ViewListParams.builder().from(params).endingBefore(objects().first().id()).build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - ViewListParams.builder().from(params).startingAfter(objects().last().id()).build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt index a3879aa6..88c4c372 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt @@ -56,13 +56,9 @@ private constructor( } return if (params.endingBefore().isPresent) { - Optional.of( - ViewListParams.builder().from(params).endingBefore(objects().first().id()).build() - ) + Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) } else { - Optional.of( - ViewListParams.builder().from(params).startingAfter(objects().last().id()).build() - ) + Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) } } From c89be141b9a48e6af20861a6fcd7c8d8e5f3ddcf Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 29 Mar 2025 00:09:38 +0000 Subject: [PATCH 17/42] codegen metadata --- .stats.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.stats.yml b/.stats.yml index 5411d578..b047325f 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 110 openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/manugoyal%2Fbraintrust-sdk-f0d64ce0e0efde75f9c171f7f3c3d4a72f00a77abb3bc5a7d65b7be1e715689b.yml openapi_spec_hash: a027e48cc6aea2fab3cbdd38f4081119 -config_hash: 8b538e7757a50832472e61dd2f54bcfc +config_hash: d9a5a1c2d71a5cd8deee0f478049efae From e71f0530ae5462de1089e41b3fefaaf18c140581 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 29 Mar 2025 03:05:04 +0000 Subject: [PATCH 18/42] fix(client): don't call `validate()` during deserialization if we don't have to (#173) --- .../com/braintrustdata/api/core/BaseDeserializer.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/BaseDeserializer.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/BaseDeserializer.kt index 64d8a5b3..901fcf3c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/BaseDeserializer.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/BaseDeserializer.kt @@ -1,5 +1,6 @@ package com.braintrustdata.api.core +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.core.ObjectCodec import com.fasterxml.jackson.core.type.TypeReference @@ -29,6 +30,13 @@ abstract class BaseDeserializer(type: KClass) : protected abstract fun ObjectCodec.deserialize(node: JsonNode): T + protected fun ObjectCodec.deserialize(node: JsonNode, type: TypeReference): T = + try { + readValue(treeAsTokens(node), type) + } catch (e: Exception) { + throw BraintrustInvalidDataException("Error deserializing", e) + } + protected fun ObjectCodec.tryDeserialize( node: JsonNode, type: TypeReference, From 63e2b2ccb213bf215441d4c74dd4aa43f3697481 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 1 Apr 2025 06:56:40 +0000 Subject: [PATCH 19/42] fix(client): limit json deserialization coercion (#174) --- braintrust-java-core/build.gradle.kts | 1 + .../braintrustdata/api/core/ObjectMappers.kt | 57 +++++++++++ .../api/core/ObjectMappersTest.kt | 81 ++++++++++++++++ .../api/core/http/SerializerTest.kt | 97 ------------------- 4 files changed, 139 insertions(+), 97 deletions(-) create mode 100644 braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/ObjectMappersTest.kt delete mode 100755 braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/SerializerTest.kt diff --git a/braintrust-java-core/build.gradle.kts b/braintrust-java-core/build.gradle.kts index 1fd4b0fd..839637a1 100755 --- a/braintrust-java-core/build.gradle.kts +++ b/braintrust-java-core/build.gradle.kts @@ -34,6 +34,7 @@ dependencies { testImplementation("org.assertj:assertj-core:3.25.3") testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3") testImplementation("org.junit.jupiter:junit-jupiter-params:5.9.3") + testImplementation("org.junit-pioneer:junit-pioneer:1.9.1") testImplementation("org.mockito:mockito-core:5.14.2") testImplementation("org.mockito:mockito-junit-jupiter:5.14.2") testImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0") diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ObjectMappers.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ObjectMappers.kt index f6ed60e5..9e7a7599 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ObjectMappers.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ObjectMappers.kt @@ -8,8 +8,11 @@ import com.fasterxml.jackson.databind.DeserializationFeature import com.fasterxml.jackson.databind.MapperFeature import com.fasterxml.jackson.databind.SerializationFeature import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.cfg.CoercionAction +import com.fasterxml.jackson.databind.cfg.CoercionInputShape import com.fasterxml.jackson.databind.json.JsonMapper import com.fasterxml.jackson.databind.module.SimpleModule +import com.fasterxml.jackson.databind.type.LogicalType import com.fasterxml.jackson.datatype.jdk8.Jdk8Module import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule import com.fasterxml.jackson.module.kotlin.kotlinModule @@ -21,6 +24,60 @@ fun jsonMapper(): JsonMapper = .addModule(Jdk8Module()) .addModule(JavaTimeModule()) .addModule(SimpleModule().addSerializer(InputStreamJsonSerializer)) + .withCoercionConfig(LogicalType.Boolean) { + it.setCoercion(CoercionInputShape.Integer, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Float, CoercionAction.Fail) + .setCoercion(CoercionInputShape.String, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Array, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Object, CoercionAction.Fail) + } + .withCoercionConfig(LogicalType.Integer) { + it.setCoercion(CoercionInputShape.Boolean, CoercionAction.Fail) + .setCoercion(CoercionInputShape.String, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Array, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Object, CoercionAction.Fail) + } + .withCoercionConfig(LogicalType.Float) { + it.setCoercion(CoercionInputShape.Boolean, CoercionAction.Fail) + .setCoercion(CoercionInputShape.String, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Array, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Object, CoercionAction.Fail) + } + .withCoercionConfig(LogicalType.Textual) { + it.setCoercion(CoercionInputShape.Boolean, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Integer, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Float, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Array, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Object, CoercionAction.Fail) + } + .withCoercionConfig(LogicalType.Array) { + it.setCoercion(CoercionInputShape.Boolean, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Integer, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Float, CoercionAction.Fail) + .setCoercion(CoercionInputShape.String, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Object, CoercionAction.Fail) + } + .withCoercionConfig(LogicalType.Collection) { + it.setCoercion(CoercionInputShape.Boolean, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Integer, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Float, CoercionAction.Fail) + .setCoercion(CoercionInputShape.String, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Object, CoercionAction.Fail) + } + .withCoercionConfig(LogicalType.Map) { + it.setCoercion(CoercionInputShape.Boolean, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Integer, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Float, CoercionAction.Fail) + .setCoercion(CoercionInputShape.String, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Object, CoercionAction.Fail) + } + .withCoercionConfig(LogicalType.POJO) { + it.setCoercion(CoercionInputShape.Boolean, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Integer, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Float, CoercionAction.Fail) + .setCoercion(CoercionInputShape.String, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Array, CoercionAction.Fail) + } .serializationInclusion(JsonInclude.Include.NON_ABSENT) .disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE) .disable(SerializationFeature.FLUSH_AFTER_WRITE_VALUE) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/ObjectMappersTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/ObjectMappersTest.kt new file mode 100644 index 00000000..921665ce --- /dev/null +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/ObjectMappersTest.kt @@ -0,0 +1,81 @@ +package com.braintrustdata.api.core + +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.databind.exc.MismatchedInputException +import kotlin.reflect.KClass +import org.assertj.core.api.Assertions.assertThat +import org.assertj.core.api.Assertions.catchThrowable +import org.junit.jupiter.api.Test +import org.junitpioneer.jupiter.cartesian.CartesianTest + +internal class ObjectMappersTest { + + internal class ClassWithBooleanFieldPrefixedWithIs(private val isActive: JsonField) { + + @JsonProperty("is_active") @ExcludeMissing fun _isActive() = isActive + } + + @Test + fun write_whenFieldPrefixedWithIs_keepsPrefix() { + val value = ClassWithBooleanFieldPrefixedWithIs(JsonField.of(true)) + + val json = jsonMapper().writeValueAsString(value) + + assertThat(json).isEqualTo("{\"is_active\":true}") + } + + internal class Class(@get:JsonProperty("field") @JsonProperty("field") val field: String) + + enum class ShapeTestCase(val value: Any, val kClass: KClass<*>) { + STRING("Hello World!", String::class), + BOOLEAN(true, Boolean::class), + FLOAT(3.14F, Float::class), + DOUBLE(3.14, Double::class), + INTEGER(42, Int::class), + LONG(42L, Long::class), + MAP(mapOf("property" to "value"), Map::class), + CLASS(Class("Hello World!"), Class::class), + LIST(listOf(1, 2, 3), List::class); + + companion object { + val VALID_CONVERSIONS = + listOf( + FLOAT to DOUBLE, + FLOAT to INTEGER, + FLOAT to LONG, + DOUBLE to FLOAT, + DOUBLE to INTEGER, + DOUBLE to LONG, + INTEGER to FLOAT, + INTEGER to DOUBLE, + INTEGER to LONG, + LONG to FLOAT, + LONG to DOUBLE, + LONG to INTEGER, + CLASS to MAP, + // These aren't actually valid, but coercion configs don't work for String until + // v2.14.0: https://github.com/FasterXML/jackson-databind/issues/3240 + // We currently test on v2.13.4. + BOOLEAN to STRING, + FLOAT to STRING, + DOUBLE to STRING, + INTEGER to STRING, + LONG to STRING, + ) + } + } + + @CartesianTest + fun read(@CartesianTest.Enum shape1: ShapeTestCase, @CartesianTest.Enum shape2: ShapeTestCase) { + val jsonMapper = jsonMapper() + val json = jsonMapper.writeValueAsString(shape1.value) + + val e = catchThrowable { jsonMapper.readValue(json, shape2.kClass.java) } + + if (shape1 == shape2 || shape1 to shape2 in ShapeTestCase.VALID_CONVERSIONS) { + assertThat(e).isNull() + } else { + assertThat(e).isInstanceOf(MismatchedInputException::class.java) + } + } +} diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/SerializerTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/SerializerTest.kt deleted file mode 100755 index 3fa27790..00000000 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/SerializerTest.kt +++ /dev/null @@ -1,97 +0,0 @@ -package com.braintrustdata.api.core.http - -import com.braintrustdata.api.core.* -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import java.util.* -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class SerializerTest { - @JsonDeserialize(builder = ClassWithBooleanFieldPrefixedWithIs.Builder::class) - class ClassWithBooleanFieldPrefixedWithIs - private constructor( - private val isActive: JsonField, - private val additionalProperties: Map, - ) { - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun isActive(): Boolean? = isActive.getNullable("is_active") - - @JsonProperty("is_active") @ExcludeMissing fun _isActive() = isActive - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun validate() = apply { - if (!validated) { - isActive() - validated = true - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is ClassWithBooleanFieldPrefixedWithIs && - isActive == other.isActive && - additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = Objects.hash(isActive, additionalProperties) - } - return hashCode - } - - override fun toString() = - "MyClass{isActive=$isActive, additionalProperties=$additionalProperties}" - - companion object { - fun builder() = Builder() - } - - class Builder internal constructor() { - - private var isActive: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - fun isActive(isActive: Boolean) = isActive(JsonField.of(isActive)) - - @JsonProperty("is_active") - @ExcludeMissing - fun isActive(isActive: JsonField) = apply { this.isActive = isActive } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun build(): ClassWithBooleanFieldPrefixedWithIs = - ClassWithBooleanFieldPrefixedWithIs(isActive, additionalProperties.toImmutable()) - } - } - - @Test - fun serializeBooleanPrefixedWithIs() { - val value = ClassWithBooleanFieldPrefixedWithIs.builder().isActive(true).build() - assertThat(jsonMapper().writeValueAsString(value)).isEqualTo("{\"is_active\":true}") - } -} From 8d7b939c590714e4344ea80d16b06414154cb691 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 2 Apr 2025 09:22:01 +0000 Subject: [PATCH 20/42] fix: pluralize `list` response variables (#175) --- .../api/services/async/EnvVarServiceAsyncTest.kt | 6 +++--- .../api/services/blocking/EnvVarServiceTest.kt | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/EnvVarServiceAsyncTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/EnvVarServiceAsyncTest.kt index 9d95d5e8..f17f8a4e 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/EnvVarServiceAsyncTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/EnvVarServiceAsyncTest.kt @@ -91,7 +91,7 @@ internal class EnvVarServiceAsyncTest { .build() val envVarServiceAsync = client.envVars() - val envVarFuture = + val envVarsFuture = envVarServiceAsync.list( EnvVarListParams.builder() .envVarName("env_var_name") @@ -102,8 +102,8 @@ internal class EnvVarServiceAsyncTest { .build() ) - val envVar = envVarFuture.get() - envVar.validate() + val envVars = envVarsFuture.get() + envVars.validate() } @Test diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/EnvVarServiceTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/EnvVarServiceTest.kt index 77382bfc..d57db964 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/EnvVarServiceTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/EnvVarServiceTest.kt @@ -88,7 +88,7 @@ internal class EnvVarServiceTest { .build() val envVarService = client.envVars() - val envVar = + val envVars = envVarService.list( EnvVarListParams.builder() .envVarName("env_var_name") @@ -99,7 +99,7 @@ internal class EnvVarServiceTest { .build() ) - envVar.validate() + envVars.validate() } @Test From 7fe60b33c4097370f473c30564fccb8ce55e062a Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 2 Apr 2025 09:57:59 +0000 Subject: [PATCH 21/42] feat(client): make union deserialization more robust (#176) feat(client): add enum validation method chore(client): remove unnecessary json state from some query param classes chore(internal): add json roundtripping tests chore(internal): add invalid json deserialization tests --- .../api/core/BaseDeserializer.kt | 33 +- .../com/braintrustdata/api/core/Utils.kt | 28 + .../com/braintrustdata/api/models/AISecret.kt | 42 + .../com/braintrustdata/api/models/Acl.kt | 32 +- .../api/models/AclBatchUpdateParams.kt | 79 +- .../api/models/AclBatchUpdateResponse.kt | 19 + .../api/models/AclCreateParams.kt | 30 +- .../api/models/AclFindAndDeleteParams.kt | 30 +- .../braintrustdata/api/models/AclListPage.kt | 9 + .../api/models/AclListPageAsync.kt | 9 + .../api/models/AclListParams.kt | 69 +- .../api/models/AclObjectType.kt | 26 + .../api/models/AiSecretCreateParams.kt | 40 + .../api/models/AiSecretFindAndDeleteParams.kt | 18 + .../api/models/AiSecretListPage.kt | 9 + .../api/models/AiSecretListPageAsync.kt | 9 + .../api/models/AiSecretListParams.kt | 128 +-- .../api/models/AiSecretReplaceParams.kt | 40 + .../api/models/AiSecretUpdateParams.kt | 39 + .../com/braintrustdata/api/models/ApiKey.kt | 22 + .../api/models/ApiKeyCreateParams.kt | 18 + .../api/models/ApiKeyListPage.kt | 9 + .../api/models/ApiKeyListPageAsync.kt | 9 + .../api/models/ApiKeyListParams.kt | 69 +- .../models/ChatCompletionContentPartImage.kt | 96 +- .../models/ChatCompletionContentPartText.kt | 47 +- .../models/ChatCompletionMessageToolCall.kt | 67 +- .../braintrustdata/api/models/CodeBundle.kt | 389 ++++++- .../api/models/CreateApiKeyOutput.kt | 23 + .../api/models/CrossObjectInsertResponse.kt | 73 ++ .../braintrustdata/api/models/DataSummary.kt | 15 + .../com/braintrustdata/api/models/Dataset.kt | 42 + .../api/models/DatasetCreateParams.kt | 39 + .../braintrustdata/api/models/DatasetEvent.kt | 43 + .../api/models/DatasetFeedbackParams.kt | 19 + .../api/models/DatasetFetchPostParams.kt | 22 + .../api/models/DatasetInsertParams.kt | 19 + .../api/models/DatasetListPage.kt | 9 + .../api/models/DatasetListPageAsync.kt | 9 + .../api/models/DatasetListParams.kt | 69 +- .../api/models/DatasetUpdateParams.kt | 38 + .../com/braintrustdata/api/models/EnvVar.kt | 51 +- .../api/models/EnvVarCreateParams.kt | 50 +- .../api/models/EnvVarListParams.kt | 69 +- .../api/models/EnvVarListResponse.kt | 18 + .../api/models/EnvVarObjectType.kt | 26 + .../api/models/EnvVarReplaceParams.kt | 50 +- .../api/models/EnvVarUpdateParams.kt | 18 + .../api/models/EvalCreateParams.kt | 980 ++++++++++++++-- .../braintrustdata/api/models/Experiment.kt | 48 + .../api/models/ExperimentCreateParams.kt | 45 + .../api/models/ExperimentEvent.kt | 108 ++ .../api/models/ExperimentFeedbackParams.kt | 19 + .../api/models/ExperimentFetchPostParams.kt | 22 + .../api/models/ExperimentInsertParams.kt | 19 + .../api/models/ExperimentListPage.kt | 9 + .../api/models/ExperimentListPageAsync.kt | 9 + .../api/models/ExperimentListParams.kt | 69 +- .../api/models/ExperimentUpdateParams.kt | 43 + .../api/models/FeedbackDatasetItem.kt | 68 +- .../api/models/FeedbackExperimentItem.kt | 87 +- .../api/models/FeedbackProjectLogsItem.kt | 87 +- .../api/models/FeedbackResponseSchema.kt | 45 +- .../api/models/FetchDatasetEventsResponse.kt | 18 + .../models/FetchExperimentEventsResponse.kt | 18 + .../models/FetchProjectLogsEventsResponse.kt | 18 + .../com/braintrustdata/api/models/Function.kt | 576 +++++++++- .../api/models/FunctionCreateParams.kt | 524 ++++++++- .../api/models/FunctionInvokeParams.kt | 780 +++++++++++-- .../api/models/FunctionInvokeResponse.kt | 16 + .../api/models/FunctionListPage.kt | 9 + .../api/models/FunctionListPageAsync.kt | 9 + .../api/models/FunctionListParams.kt | 69 +- .../api/models/FunctionReplaceParams.kt | 524 ++++++++- .../api/models/FunctionUpdateParams.kt | 452 +++++++- .../com/braintrustdata/api/models/Group.kt | 25 + .../api/models/GroupCreateParams.kt | 22 + .../api/models/GroupListPage.kt | 9 + .../api/models/GroupListPageAsync.kt | 9 + .../api/models/GroupListParams.kt | 69 +- .../api/models/GroupReplaceParams.kt | 22 + .../api/models/GroupUpdateParams.kt | 23 + .../api/models/InsertDatasetEvent.kt | 44 + .../api/models/InsertEventsResponse.kt | 16 + .../api/models/InsertExperimentEvent.kt | 108 ++ .../api/models/InsertProjectLogsEvent.kt | 108 ++ .../api/models/MetricSummary.kt | 22 + .../api/models/ObjectReference.kt | 50 +- .../api/models/OnlineScoreConfig.kt | 180 ++- .../braintrustdata/api/models/Organization.kt | 23 + .../api/models/OrganizationListPage.kt | 9 + .../api/models/OrganizationListPageAsync.kt | 9 + .../api/models/OrganizationListParams.kt | 69 +- .../models/OrganizationMemberUpdateParams.kt | 63 + .../api/models/OrganizationUpdateParams.kt | 22 + .../models/PatchOrganizationMembersOutput.kt | 48 +- .../braintrustdata/api/models/Permission.kt | 26 + .../com/braintrustdata/api/models/Project.kt | 23 + .../api/models/ProjectCreateParams.kt | 18 + .../api/models/ProjectListPage.kt | 9 + .../api/models/ProjectListPageAsync.kt | 9 + .../api/models/ProjectListParams.kt | 69 +- .../api/models/ProjectLogFeedbackParams.kt | 19 + .../api/models/ProjectLogFetchPostParams.kt | 22 + .../api/models/ProjectLogInsertParams.kt | 19 + .../api/models/ProjectLogsEvent.kt | 138 ++- .../braintrustdata/api/models/ProjectScore.kt | 118 +- .../api/models/ProjectScoreCategory.kt | 17 + .../api/models/ProjectScoreConfig.kt | 19 + .../api/models/ProjectScoreCreateParams.kt | 115 +- .../api/models/ProjectScoreListPage.kt | 9 + .../api/models/ProjectScoreListPageAsync.kt | 9 + .../api/models/ProjectScoreListParams.kt | 129 +-- .../api/models/ProjectScoreReplaceParams.kt | 115 +- .../api/models/ProjectScoreType.kt | 26 + .../api/models/ProjectScoreUpdateParams.kt | 114 +- .../api/models/ProjectSettings.kt | 69 +- .../braintrustdata/api/models/ProjectTag.kt | 23 + .../api/models/ProjectTagCreateParams.kt | 21 + .../api/models/ProjectTagListPage.kt | 9 + .../api/models/ProjectTagListPageAsync.kt | 9 + .../api/models/ProjectTagListParams.kt | 69 +- .../api/models/ProjectTagReplaceParams.kt | 21 + .../api/models/ProjectTagUpdateParams.kt | 20 + .../api/models/ProjectUpdateParams.kt | 19 + .../com/braintrustdata/api/models/Prompt.kt | 105 +- .../api/models/PromptCreateParams.kt | 53 +- .../braintrustdata/api/models/PromptData.kt | 1024 +++++++++++++++-- .../api/models/PromptListPage.kt | 9 + .../api/models/PromptListPageAsync.kt | 9 + .../api/models/PromptListParams.kt | 69 +- .../api/models/PromptOptions.kt | 849 ++++++++++++-- .../api/models/PromptReplaceParams.kt | 53 +- .../api/models/PromptUpdateParams.kt | 22 + .../com/braintrustdata/api/models/RepoInfo.kt | 25 + .../com/braintrustdata/api/models/Role.kt | 48 +- .../api/models/RoleCreateParams.kt | 45 +- .../braintrustdata/api/models/RoleListPage.kt | 9 + .../api/models/RoleListPageAsync.kt | 9 + .../api/models/RoleListParams.kt | 69 +- .../api/models/RoleReplaceParams.kt | 45 +- .../api/models/RoleUpdateParams.kt | 70 +- .../braintrustdata/api/models/ScoreSummary.kt | 21 + .../api/models/SpanAttributes.kt | 19 +- .../braintrustdata/api/models/SpanIFrame.kt | 25 + .../api/models/SpanIframeCreateParams.kt | 22 + .../api/models/SpanIframeListPage.kt | 9 + .../api/models/SpanIframeListPageAsync.kt | 9 + .../api/models/SpanIframeListParams.kt | 69 +- .../api/models/SpanIframeReplaceParams.kt | 22 + .../api/models/SpanIframeUpdateParams.kt | 21 + .../com/braintrustdata/api/models/SpanType.kt | 26 + .../api/models/SummarizeDatasetResponse.kt | 21 + .../api/models/SummarizeExperimentResponse.kt | 59 + .../com/braintrustdata/api/models/User.kt | 22 + .../braintrustdata/api/models/UserListPage.kt | 9 + .../api/models/UserListPageAsync.kt | 9 + .../api/models/UserListParams.kt | 246 +--- .../com/braintrustdata/api/models/View.kt | 57 +- .../api/models/ViewCreateParams.kt | 56 +- .../com/braintrustdata/api/models/ViewData.kt | 15 + .../api/models/ViewDataSearch.kt | 20 + .../api/models/ViewDeleteParams.kt | 22 +- .../braintrustdata/api/models/ViewListPage.kt | 9 + .../api/models/ViewListPageAsync.kt | 9 + .../api/models/ViewListParams.kt | 69 +- .../braintrustdata/api/models/ViewOptions.kt | 58 + .../api/models/ViewReplaceParams.kt | 56 +- .../com/braintrustdata/api/models/ViewType.kt | 26 + .../api/models/ViewUpdateParams.kt | 55 +- .../braintrustdata/api/models/AISecretTest.kt | 30 + .../api/models/AclBatchUpdateResponseTest.kt | 46 + .../com/braintrustdata/api/models/AclTest.kt | 25 + .../braintrustdata/api/models/ApiKeyTest.kt | 21 + .../ChatCompletionContentPartImageTest.kt | 26 + .../ChatCompletionContentPartTextTest.kt | 21 + .../ChatCompletionMessageToolCallTest.kt | 27 + .../api/models/CodeBundleTest.kt | 37 + .../api/models/CreateApiKeyOutputTest.kt | 25 + .../models/CrossObjectInsertResponseTest.kt | 42 + .../api/models/DataSummaryTest.kt | 16 + .../api/models/DatasetEventTest.kt | 39 + .../braintrustdata/api/models/DatasetTest.kt | 27 + .../api/models/EnvVarListResponseTest.kt | 28 + .../braintrustdata/api/models/EnvVarTest.kt | 21 + .../api/models/ExperimentEventTest.kt | 67 ++ .../api/models/ExperimentTest.kt | 48 + .../api/models/FeedbackDatasetItemTest.kt | 27 + .../api/models/FeedbackExperimentItemTest.kt | 33 + .../api/models/FeedbackProjectLogsItemTest.kt | 33 + .../api/models/FeedbackResponseSchemaTest.kt | 17 + .../models/FetchDatasetEventsResponseTest.kt | 44 + .../FetchExperimentEventsResponseTest.kt | 75 ++ .../FetchProjectLogsEventsResponseTest.kt | 76 ++ .../api/models/FunctionInvokeResponseTest.kt | 17 + .../braintrustdata/api/models/FunctionTest.kt | 132 +++ .../braintrustdata/api/models/GroupTest.kt | 24 + .../api/models/InsertDatasetEventTest.kt | 40 + .../api/models/InsertEventsResponseTest.kt | 16 + .../api/models/InsertExperimentEventTest.kt | 67 ++ .../api/models/InsertProjectLogsEventTest.kt | 67 ++ .../api/models/MetricSummaryTest.kt | 24 + .../api/models/ObjectReferenceTest.kt | 23 + .../api/models/OnlineScoreConfigTest.kt | 27 + .../api/models/OrganizationTest.kt | 25 + .../PatchOrganizationMembersOutputTest.kt | 22 + .../api/models/ProjectLogsEventTest.kt | 68 ++ .../api/models/ProjectScoreCategoryTest.kt | 16 + .../api/models/ProjectScoreConfigTest.kt | 33 + .../api/models/ProjectScoreTest.kt | 48 + .../api/models/ProjectSettingsTest.kt | 28 + .../api/models/ProjectTagTest.kt | 25 + .../braintrustdata/api/models/ProjectTest.kt | 35 + .../api/models/PromptDataTest.kt | 89 ++ .../api/models/PromptOptionsTest.kt | 50 + .../braintrustdata/api/models/PromptTest.kt | 111 ++ .../braintrustdata/api/models/RepoInfoTest.kt | 27 + .../com/braintrustdata/api/models/RoleTest.kt | 29 + .../api/models/ScoreSummaryTest.kt | 23 + .../api/models/SpanAttributesTest.kt | 16 + .../api/models/SpanIFrameTest.kt | 27 + .../models/SummarizeDatasetResponseTest.kt | 23 + .../models/SummarizeExperimentResponseTest.kt | 56 + .../com/braintrustdata/api/models/UserTest.kt | 21 + .../api/models/ViewDataSearchTest.kt | 22 + .../braintrustdata/api/models/ViewDataTest.kt | 26 + .../api/models/ViewOptionsTest.kt | 32 + .../com/braintrustdata/api/models/ViewTest.kt | 53 + 228 files changed, 12673 insertions(+), 2115 deletions(-) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/BaseDeserializer.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/BaseDeserializer.kt index 901fcf3c..3ebb507f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/BaseDeserializer.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/BaseDeserializer.kt @@ -1,6 +1,5 @@ package com.braintrustdata.api.core -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.core.ObjectCodec import com.fasterxml.jackson.core.type.TypeReference @@ -8,7 +7,6 @@ import com.fasterxml.jackson.databind.BeanProperty import com.fasterxml.jackson.databind.DeserializationContext import com.fasterxml.jackson.databind.JavaType import com.fasterxml.jackson.databind.JsonDeserializer -import com.fasterxml.jackson.databind.JsonMappingException import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.deser.ContextualDeserializer import com.fasterxml.jackson.databind.deser.std.StdDeserializer @@ -30,38 +28,17 @@ abstract class BaseDeserializer(type: KClass) : protected abstract fun ObjectCodec.deserialize(node: JsonNode): T - protected fun ObjectCodec.deserialize(node: JsonNode, type: TypeReference): T = + protected fun ObjectCodec.tryDeserialize(node: JsonNode, type: TypeReference): T? = try { readValue(treeAsTokens(node), type) } catch (e: Exception) { - throw BraintrustInvalidDataException("Error deserializing", e) - } - - protected fun ObjectCodec.tryDeserialize( - node: JsonNode, - type: TypeReference, - validate: (T) -> Unit = {}, - ): T? { - return try { - readValue(treeAsTokens(node), type).apply(validate) - } catch (e: JsonMappingException) { - null - } catch (e: RuntimeException) { null } - } - protected fun ObjectCodec.tryDeserialize( - node: JsonNode, - type: JavaType, - validate: (T) -> Unit = {}, - ): T? { - return try { - readValue(treeAsTokens(node), type).apply(validate) - } catch (e: JsonMappingException) { - null - } catch (e: RuntimeException) { + protected fun ObjectCodec.tryDeserialize(node: JsonNode, type: JavaType): T? = + try { + readValue(treeAsTokens(node), type) + } catch (e: Exception) { null } - } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Utils.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Utils.kt index 6761ce6a..6f9fb155 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Utils.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Utils.kt @@ -25,6 +25,34 @@ internal fun , V> SortedMap.toImmutable(): SortedMap> Sequence.allMaxBy(selector: (T) -> R): List { + var maxValue: R? = null + val maxElements = mutableListOf() + + val iterator = iterator() + while (iterator.hasNext()) { + val element = iterator.next() + val value = selector(element) + if (maxValue == null || value > maxValue) { + maxValue = value + maxElements.clear() + maxElements.add(element) + } else if (value == maxValue) { + maxElements.add(element) + } + } + + return maxElements +} + /** * Returns whether [this] is equal to [other]. * diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AISecret.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AISecret.kt index 40528d3e..059217c1 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AISecret.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AISecret.kt @@ -396,6 +396,30 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (orgId.asKnown().isPresent) 1 else 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (previewSecret.asKnown().isPresent) 1 else 0) + + (if (type.asKnown().isPresent) 1 else 0) + + (if (updatedAt.asKnown().isPresent) 1 else 0) + class Metadata @JsonCreator private constructor( @@ -462,6 +486,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Acl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Acl.kt index 57225fc1..dd4f11ae 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Acl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Acl.kt @@ -513,16 +513,42 @@ private constructor( id() _objectOrgId() objectId() - objectType() + objectType().validate() created() groupId() - permission() - restrictObjectType() + permission().ifPresent { it.validate() } + restrictObjectType().ifPresent { it.validate() } roleId() userId() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (_objectOrgId.asKnown().isPresent) 1 else 0) + + (if (objectId.asKnown().isPresent) 1 else 0) + + (objectType.asKnown().getOrNull()?.validity() ?: 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (if (groupId.asKnown().isPresent) 1 else 0) + + (permission.asKnown().getOrNull()?.validity() ?: 0) + + (restrictObjectType.asKnown().getOrNull()?.validity() ?: 0) + + (if (roleId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateParams.kt index 8b930279..56f17eb3 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateParams.kt @@ -527,6 +527,25 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (addAcls.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (removeAcls.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -939,15 +958,39 @@ private constructor( } objectId() - objectType() + objectType().validate() groupId() - permission() - restrictObjectType() + permission().ifPresent { it.validate() } + restrictObjectType().ifPresent { it.validate() } roleId() userId() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (objectId.asKnown().isPresent) 1 else 0) + + (objectType.asKnown().getOrNull()?.validity() ?: 0) + + (if (groupId.asKnown().isPresent) 1 else 0) + + (permission.asKnown().getOrNull()?.validity() ?: 0) + + (restrictObjectType.asKnown().getOrNull()?.validity() ?: 0) + + (if (roleId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1360,15 +1403,39 @@ private constructor( } objectId() - objectType() + objectType().validate() groupId() - permission() - restrictObjectType() + permission().ifPresent { it.validate() } + restrictObjectType().ifPresent { it.validate() } roleId() userId() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (objectId.asKnown().isPresent) 1 else 0) + + (objectType.asKnown().getOrNull()?.validity() ?: 0) + + (if (groupId.asKnown().isPresent) 1 else 0) + + (permission.asKnown().getOrNull()?.validity() ?: 0) + + (restrictObjectType.asKnown().getOrNull()?.validity() ?: 0) + + (if (roleId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateResponse.kt index f6cd529d..901575b1 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateResponse.kt @@ -16,6 +16,7 @@ import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.util.Collections import java.util.Objects +import kotlin.jvm.optionals.getOrNull class AclBatchUpdateResponse private constructor( @@ -242,6 +243,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (addedAcls.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (removedAcls.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclCreateParams.kt index 1925e4ef..3577ae1d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclCreateParams.kt @@ -821,15 +821,39 @@ private constructor( } objectId() - objectType() + objectType().validate() groupId() - permission() - restrictObjectType() + permission().ifPresent { it.validate() } + restrictObjectType().ifPresent { it.validate() } roleId() userId() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (objectId.asKnown().isPresent) 1 else 0) + + (objectType.asKnown().getOrNull()?.validity() ?: 0) + + (if (groupId.asKnown().isPresent) 1 else 0) + + (permission.asKnown().getOrNull()?.validity() ?: 0) + + (restrictObjectType.asKnown().getOrNull()?.validity() ?: 0) + + (if (roleId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParams.kt index f2c9e1ab..d0a760d4 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParams.kt @@ -822,15 +822,39 @@ private constructor( } objectId() - objectType() + objectType().validate() groupId() - permission() - restrictObjectType() + permission().ifPresent { it.validate() } + restrictObjectType().ifPresent { it.validate() } roleId() userId() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (objectId.asKnown().isPresent) 1 else 0) + + (objectType.asKnown().getOrNull()?.validity() ?: 0) + + (if (groupId.asKnown().isPresent) 1 else 0) + + (permission.asKnown().getOrNull()?.validity() ?: 0) + + (restrictObjectType.asKnown().getOrNull()?.validity() ?: 0) + + (if (roleId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt index 98928291..ef35ed0b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.AclService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -111,6 +112,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt index 0e59859a..09126eb6 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.AclServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -113,6 +114,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListParams.kt index 13915530..238ae30f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListParams.kt @@ -2,22 +2,11 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.BaseDeserializer -import com.braintrustdata.api.core.BaseSerializer -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.errors.BraintrustInvalidDataException -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -327,13 +316,10 @@ private constructor( * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times */ - @JsonDeserialize(using = Ids.Deserializer::class) - @JsonSerialize(using = Ids.Serializer::class) class Ids private constructor( private val string: String? = null, private val strings: List? = null, - private val _json: JsonValue? = null, ) { fun string(): Optional = Optional.ofNullable(string) @@ -348,15 +334,12 @@ private constructor( fun asStrings(): List = strings.getOrThrow("strings") - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { string != null -> visitor.visitString(string) strings != null -> visitor.visitStrings(strings) - else -> visitor.unknown(_json) + else -> throw IllegalStateException("Invalid Ids") } - } override fun equals(other: Any?): Boolean { if (this === other) { @@ -372,7 +355,6 @@ private constructor( when { string != null -> "Ids{string=$string}" strings != null -> "Ids{strings=$strings}" - _json != null -> "Ids{_unknown=$_json}" else -> throw IllegalStateException("Invalid Ids") } @@ -389,51 +371,6 @@ private constructor( fun visitString(string: String): T fun visitStrings(strings: List): T - - /** - * Maps an unknown variant of [Ids] to a value of type [T]. - * - * An instance of [Ids] can contain an unknown variant if it was deserialized from data - * that doesn't match any known variant. For example, if the SDK is on an older version - * than the API, then the API may respond with new variants that the SDK is unaware of. - * - * @throws BraintrustInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown Ids: $json") - } - } - - internal class Deserializer : BaseDeserializer(Ids::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Ids { - val json = JsonValue.fromJsonNode(node) - - tryDeserialize(node, jacksonTypeRef())?.let { - return Ids(string = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return Ids(strings = it, _json = json) - } - - return Ids(_json = json) - } - } - - internal class Serializer : BaseSerializer(Ids::class) { - - override fun serialize( - value: Ids, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.string != null -> generator.writeObject(value.string) - value.strings != null -> generator.writeObject(value.strings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Ids") - } - } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclObjectType.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclObjectType.kt index 90f9091e..727accde 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclObjectType.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclObjectType.kt @@ -148,6 +148,32 @@ class AclObjectType @JsonCreator private constructor(private val value: JsonFiel fun asString(): String = _value().asString().orElseThrow { BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): AclObjectType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt index 4b1c5c19..c8affb77 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt @@ -631,6 +631,28 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (orgName.asKnown().isPresent) 1 else 0) + + (if (secret.asKnown().isPresent) 1 else 0) + + (if (type.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -715,6 +737,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParams.kt index 4ebf4266..a934bad7 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParams.kt @@ -429,6 +429,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + (if (orgName.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt index c3c09ba0..ebeef363 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.AiSecretService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -111,6 +112,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt index 861ba05f..486a136d 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.AiSecretServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -116,6 +117,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListParams.kt index ce8926c5..dd7ef4bd 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListParams.kt @@ -2,21 +2,10 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.BaseDeserializer -import com.braintrustdata.api.core.BaseSerializer -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.errors.BraintrustInvalidDataException -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -344,13 +333,10 @@ private constructor( } .build() - @JsonDeserialize(using = AiSecretType.Deserializer::class) - @JsonSerialize(using = AiSecretType.Serializer::class) class AiSecretType private constructor( private val string: String? = null, private val strings: List? = null, - private val _json: JsonValue? = null, ) { fun string(): Optional = Optional.ofNullable(string) @@ -365,15 +351,12 @@ private constructor( fun asStrings(): List = strings.getOrThrow("strings") - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { string != null -> visitor.visitString(string) strings != null -> visitor.visitStrings(strings) - else -> visitor.unknown(_json) + else -> throw IllegalStateException("Invalid AiSecretType") } - } override fun equals(other: Any?): Boolean { if (this === other) { @@ -389,7 +372,6 @@ private constructor( when { string != null -> "AiSecretType{string=$string}" strings != null -> "AiSecretType{strings=$strings}" - _json != null -> "AiSecretType{_unknown=$_json}" else -> throw IllegalStateException("Invalid AiSecretType") } @@ -409,52 +391,6 @@ private constructor( fun visitString(string: String): T fun visitStrings(strings: List): T - - /** - * Maps an unknown variant of [AiSecretType] to a value of type [T]. - * - * An instance of [AiSecretType] can contain an unknown variant if it was deserialized - * from data that doesn't match any known variant. For example, if the SDK is on an - * older version than the API, then the API may respond with new variants that the SDK - * is unaware of. - * - * @throws BraintrustInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown AiSecretType: $json") - } - } - - internal class Deserializer : BaseDeserializer(AiSecretType::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): AiSecretType { - val json = JsonValue.fromJsonNode(node) - - tryDeserialize(node, jacksonTypeRef())?.let { - return AiSecretType(string = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return AiSecretType(strings = it, _json = json) - } - - return AiSecretType(_json = json) - } - } - - internal class Serializer : BaseSerializer(AiSecretType::class) { - - override fun serialize( - value: AiSecretType, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.string != null -> generator.writeObject(value.string) - value.strings != null -> generator.writeObject(value.strings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid AiSecretType") - } - } } } @@ -462,13 +398,10 @@ private constructor( * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times */ - @JsonDeserialize(using = Ids.Deserializer::class) - @JsonSerialize(using = Ids.Serializer::class) class Ids private constructor( private val string: String? = null, private val strings: List? = null, - private val _json: JsonValue? = null, ) { fun string(): Optional = Optional.ofNullable(string) @@ -483,15 +416,12 @@ private constructor( fun asStrings(): List = strings.getOrThrow("strings") - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { string != null -> visitor.visitString(string) strings != null -> visitor.visitStrings(strings) - else -> visitor.unknown(_json) + else -> throw IllegalStateException("Invalid Ids") } - } override fun equals(other: Any?): Boolean { if (this === other) { @@ -507,7 +437,6 @@ private constructor( when { string != null -> "Ids{string=$string}" strings != null -> "Ids{strings=$strings}" - _json != null -> "Ids{_unknown=$_json}" else -> throw IllegalStateException("Invalid Ids") } @@ -524,51 +453,6 @@ private constructor( fun visitString(string: String): T fun visitStrings(strings: List): T - - /** - * Maps an unknown variant of [Ids] to a value of type [T]. - * - * An instance of [Ids] can contain an unknown variant if it was deserialized from data - * that doesn't match any known variant. For example, if the SDK is on an older version - * than the API, then the API may respond with new variants that the SDK is unaware of. - * - * @throws BraintrustInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown Ids: $json") - } - } - - internal class Deserializer : BaseDeserializer(Ids::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Ids { - val json = JsonValue.fromJsonNode(node) - - tryDeserialize(node, jacksonTypeRef())?.let { - return Ids(string = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return Ids(strings = it, _json = json) - } - - return Ids(_json = json) - } - } - - internal class Serializer : BaseSerializer(Ids::class) { - - override fun serialize( - value: Ids, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.string != null -> generator.writeObject(value.string) - value.strings != null -> generator.writeObject(value.strings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Ids") - } - } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt index 6332eda2..f7bbd5a4 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt @@ -631,6 +631,28 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (orgName.asKnown().isPresent) 1 else 0) + + (if (secret.asKnown().isPresent) 1 else 0) + + (if (type.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -715,6 +737,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt index 861e0147..b09bec37 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt @@ -543,6 +543,27 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (secret.asKnown().isPresent) 1 else 0) + + (if (type.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -627,6 +648,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKey.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKey.kt index 1bfec88d..8d547ba7 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKey.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKey.kt @@ -319,6 +319,28 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (previewName.asKnown().isPresent) 1 else 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (if (orgId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyCreateParams.kt index 9c8de109..45681f9d 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyCreateParams.kt @@ -432,6 +432,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + (if (orgName.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt index b12a7e29..c1dd8fe5 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.ApiKeyService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -111,6 +112,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt index 2a40c262..7e2a3041 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.ApiKeyServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -113,6 +114,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListParams.kt index fa7cd183..a1fcb296 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListParams.kt @@ -2,21 +2,10 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.BaseDeserializer -import com.braintrustdata.api.core.BaseSerializer -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.errors.BraintrustInvalidDataException -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -318,13 +307,10 @@ private constructor( * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times */ - @JsonDeserialize(using = Ids.Deserializer::class) - @JsonSerialize(using = Ids.Serializer::class) class Ids private constructor( private val string: String? = null, private val strings: List? = null, - private val _json: JsonValue? = null, ) { fun string(): Optional = Optional.ofNullable(string) @@ -339,15 +325,12 @@ private constructor( fun asStrings(): List = strings.getOrThrow("strings") - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { string != null -> visitor.visitString(string) strings != null -> visitor.visitStrings(strings) - else -> visitor.unknown(_json) + else -> throw IllegalStateException("Invalid Ids") } - } override fun equals(other: Any?): Boolean { if (this === other) { @@ -363,7 +346,6 @@ private constructor( when { string != null -> "Ids{string=$string}" strings != null -> "Ids{strings=$strings}" - _json != null -> "Ids{_unknown=$_json}" else -> throw IllegalStateException("Invalid Ids") } @@ -380,51 +362,6 @@ private constructor( fun visitString(string: String): T fun visitStrings(strings: List): T - - /** - * Maps an unknown variant of [Ids] to a value of type [T]. - * - * An instance of [Ids] can contain an unknown variant if it was deserialized from data - * that doesn't match any known variant. For example, if the SDK is on an older version - * than the API, then the API may respond with new variants that the SDK is unaware of. - * - * @throws BraintrustInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown Ids: $json") - } - } - - internal class Deserializer : BaseDeserializer(Ids::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Ids { - val json = JsonValue.fromJsonNode(node) - - tryDeserialize(node, jacksonTypeRef())?.let { - return Ids(string = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return Ids(strings = it, _json = json) - } - - return Ids(_json = json) - } - } - - internal class Serializer : BaseSerializer(Ids::class) { - - override fun serialize( - value: Ids, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.string != null -> generator.writeObject(value.string) - value.strings != null -> generator.writeObject(value.strings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Ids") - } - } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImage.kt index 678e2fee..79a02da2 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImage.kt @@ -16,6 +16,7 @@ import com.fasterxml.jackson.annotation.JsonProperty import java.util.Collections import java.util.Objects import java.util.Optional +import kotlin.jvm.optionals.getOrNull class ChatCompletionContentPartImage private constructor( @@ -167,10 +168,28 @@ private constructor( } imageUrl().validate() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (imageUrl.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + class ImageUrl private constructor( private val url: JsonField, @@ -314,10 +333,29 @@ private constructor( } url() - detail() + detail().ifPresent { it.validate() } validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (url.asKnown().isPresent) 1 else 0) + + (detail.asKnown().getOrNull()?.validity() ?: 0) + class Detail @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -413,6 +451,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Detail = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -525,6 +590,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartText.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartText.kt index e78b84cf..2edc113c 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartText.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartText.kt @@ -16,6 +16,7 @@ import com.fasterxml.jackson.annotation.JsonProperty import java.util.Collections import java.util.Objects import java.util.Optional +import kotlin.jvm.optionals.getOrNull class ChatCompletionContentPartText private constructor( @@ -162,11 +163,28 @@ private constructor( return@apply } - type() + type().validate() text() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (type.asKnown().getOrNull()?.validity() ?: 0) + (if (text.asKnown().isPresent) 1 else 0) + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -248,6 +266,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionMessageToolCall.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionMessageToolCall.kt index c8b11561..fdd8a4d7 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionMessageToolCall.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionMessageToolCall.kt @@ -15,6 +15,7 @@ import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.util.Collections import java.util.Objects +import kotlin.jvm.optionals.getOrNull class ChatCompletionMessageToolCall private constructor( @@ -196,10 +197,29 @@ private constructor( id() function().validate() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (function.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + class Function private constructor( private val arguments: JsonField, @@ -355,6 +375,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (arguments.asKnown().isPresent) 1 else 0) + (if (name.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -454,6 +492,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CodeBundle.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CodeBundle.kt index b8f8e53e..25bcd6c5 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CodeBundle.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CodeBundle.kt @@ -9,6 +9,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.allMaxBy import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.errors.BraintrustInvalidDataException @@ -260,6 +261,26 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (bundleId.asKnown().isPresent) 1 else 0) + + (location.asKnown().getOrNull()?.validity() ?: 0) + + (runtimeContext.asKnown().getOrNull()?.validity() ?: 0) + + (if (preview.asKnown().isPresent) 1 else 0) + @JsonDeserialize(using = Location.Deserializer::class) @JsonSerialize(using = Location.Serializer::class) class Location @@ -283,13 +304,12 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { experiment != null -> visitor.visitExperiment(experiment) function != null -> visitor.visitFunction(function) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -312,6 +332,32 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitExperiment(experiment: Experiment) = experiment.validity() + + override fun visitFunction(function: Function) = function.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -366,16 +412,28 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): Location { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Location(experiment = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Location(function = it, _json = json) - } - - return Location(_json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Location(experiment = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Location(function = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with + // all the possible variants (e.g. deserializing from boolean). + 0 -> Location(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the first + // completely valid match, or simply the first match if none are completely + // valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } } } @@ -596,10 +654,30 @@ private constructor( evalName() position().validate() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (evalName.asKnown().isPresent) 1 else 0) + + (position.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + @JsonDeserialize(using = Position.Deserializer::class) @JsonSerialize(using = Position.Serializer::class) class Position @@ -623,13 +701,12 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { type != null -> visitor.visitType(type) scorer != null -> visitor.visitScorer(scorer) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -652,6 +729,32 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitType(type: Type) = type.validity() + + override fun visitScorer(scorer: Scorer) = scorer.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -707,16 +810,29 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): Position { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Position(type = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Position(scorer = it, _json = json) - } - - return Position(_json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Position(type = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Position(scorer = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. deserializing from + // boolean). + 0 -> Position(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use + // the first completely valid match, or simply the first match if none + // are completely valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } } } @@ -858,10 +974,27 @@ private constructor( return@apply } - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = (type.asKnown().getOrNull()?.validity() ?: 0) + class InnerType @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -954,6 +1087,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): InnerType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1146,10 +1307,29 @@ private constructor( } index() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (index.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -1238,6 +1418,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1354,6 +1562,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1539,10 +1774,29 @@ private constructor( } index() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (index.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -1627,6 +1881,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1807,11 +2088,30 @@ private constructor( return@apply } - runtime() + runtime().validate() version() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (runtime.asKnown().getOrNull()?.validity() ?: 0) + + (if (version.asKnown().isPresent) 1 else 0) + class Runtime @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -1902,6 +2202,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Runtime = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CreateApiKeyOutput.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CreateApiKeyOutput.kt index 4e55702d..aaaeab1f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CreateApiKeyOutput.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CreateApiKeyOutput.kt @@ -353,6 +353,29 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (key.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (previewName.asKnown().isPresent) 1 else 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (if (orgId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponse.kt index bd424e7a..46377149 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponse.kt @@ -215,6 +215,25 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (dataset.asKnown().getOrNull()?.validity() ?: 0) + + (experiment.asKnown().getOrNull()?.validity() ?: 0) + + (projectLogs.asKnown().getOrNull()?.validity() ?: 0) + /** A mapping from dataset id to row ids for inserted `events` */ class Dataset @JsonCreator @@ -282,6 +301,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -366,6 +403,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -450,6 +505,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DataSummary.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DataSummary.kt index 71a1b7ed..e499cfa4 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DataSummary.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DataSummary.kt @@ -144,6 +144,21 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (if (totalRecords.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Dataset.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Dataset.kt index 4eb764fc..585c5c7a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Dataset.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Dataset.kt @@ -400,6 +400,30 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (if (deletedAt.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (userId.asKnown().isPresent) 1 else 0) + /** User-controlled metadata about the dataset */ class Metadata @JsonCreator @@ -467,6 +491,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt index 8000d930..0c32f64e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt @@ -567,6 +567,27 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -652,6 +673,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetEvent.kt index fa1c48ad..50ea5813 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetEvent.kt @@ -589,6 +589,33 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (_xactId.asKnown().isPresent) 1 else 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (if (datasetId.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (rootSpanId.asKnown().isPresent) 1 else 0) + + (if (spanId.asKnown().isPresent) 1 else 0) + + (if (isRoot.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (origin.asKnown().getOrNull()?.validity() ?: 0) + + (tags.asKnown().getOrNull()?.size ?: 0) + /** * A dictionary with additional data about the test example, model outputs, or just about * anything else that's relevant, that you can use to help find and analyze examples later. For @@ -705,6 +732,22 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (if (model.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFeedbackParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFeedbackParams.kt index b568875c..1237becd 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFeedbackParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFeedbackParams.kt @@ -19,6 +19,7 @@ import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.util.Collections import java.util.Objects +import kotlin.jvm.optionals.getOrNull /** Log feedback for a set of dataset events */ class DatasetFeedbackParams @@ -402,6 +403,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (feedback.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt index 6e1d6df2..93854768 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt @@ -827,6 +827,28 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (cursor.asKnown().isPresent) 1 else 0) + + (if (limit.asKnown().isPresent) 1 else 0) + + (if (maxRootSpanId.asKnown().isPresent) 1 else 0) + + (if (maxXactId.asKnown().isPresent) 1 else 0) + + (if (version.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetInsertParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetInsertParams.kt index 4310d1a5..a1ac47a6 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetInsertParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetInsertParams.kt @@ -19,6 +19,7 @@ import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.util.Collections import java.util.Objects +import kotlin.jvm.optionals.getOrNull /** Insert a set of events into the dataset */ class DatasetInsertParams @@ -400,6 +401,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (events.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt index aebf0e48..40631053 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.DatasetService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -111,6 +112,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt index a23154ba..536ed5d0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.DatasetServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -116,6 +117,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListParams.kt index d0f311fc..5928e94b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListParams.kt @@ -2,21 +2,10 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.BaseDeserializer -import com.braintrustdata.api.core.BaseSerializer -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.errors.BraintrustInvalidDataException -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -346,13 +335,10 @@ private constructor( * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times */ - @JsonDeserialize(using = Ids.Deserializer::class) - @JsonSerialize(using = Ids.Serializer::class) class Ids private constructor( private val string: String? = null, private val strings: List? = null, - private val _json: JsonValue? = null, ) { fun string(): Optional = Optional.ofNullable(string) @@ -367,15 +353,12 @@ private constructor( fun asStrings(): List = strings.getOrThrow("strings") - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { string != null -> visitor.visitString(string) strings != null -> visitor.visitStrings(strings) - else -> visitor.unknown(_json) + else -> throw IllegalStateException("Invalid Ids") } - } override fun equals(other: Any?): Boolean { if (this === other) { @@ -391,7 +374,6 @@ private constructor( when { string != null -> "Ids{string=$string}" strings != null -> "Ids{strings=$strings}" - _json != null -> "Ids{_unknown=$_json}" else -> throw IllegalStateException("Invalid Ids") } @@ -408,51 +390,6 @@ private constructor( fun visitString(string: String): T fun visitStrings(strings: List): T - - /** - * Maps an unknown variant of [Ids] to a value of type [T]. - * - * An instance of [Ids] can contain an unknown variant if it was deserialized from data - * that doesn't match any known variant. For example, if the SDK is on an older version - * than the API, then the API may respond with new variants that the SDK is unaware of. - * - * @throws BraintrustInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown Ids: $json") - } - } - - internal class Deserializer : BaseDeserializer(Ids::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Ids { - val json = JsonValue.fromJsonNode(node) - - tryDeserialize(node, jacksonTypeRef())?.let { - return Ids(string = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return Ids(strings = it, _json = json) - } - - return Ids(_json = json) - } - } - - internal class Serializer : BaseSerializer(Ids::class) { - - override fun serialize( - value: Ids, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.string != null -> generator.writeObject(value.string) - value.strings != null -> generator.writeObject(value.strings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Ids") - } - } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt index 036b54b7..ef53de0e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt @@ -505,6 +505,26 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (description.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -590,6 +610,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVar.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVar.kt index 1369d011..5e49e6ce 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVar.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVar.kt @@ -317,12 +317,34 @@ private constructor( id() name() objectId() - objectType() + objectType().validate() created() used() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (objectId.asKnown().isPresent) 1 else 0) + + (objectType.asKnown().getOrNull()?.validity() ?: 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (if (used.asKnown().isPresent) 1 else 0) + /** The type of the object the environment variable is scoped for */ class ObjectType @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -419,6 +441,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): ObjectType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarCreateParams.kt index 6a61e390..8441ccc6 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarCreateParams.kt @@ -555,11 +555,32 @@ private constructor( name() objectId() - objectType() + objectType().validate() value() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (if (objectId.asKnown().isPresent) 1 else 0) + + (objectType.asKnown().getOrNull()?.validity() ?: 0) + + (if (value.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -674,6 +695,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): ObjectType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListParams.kt index a23dfdfe..420b7e23 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListParams.kt @@ -2,21 +2,10 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.BaseDeserializer -import com.braintrustdata.api.core.BaseSerializer -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.errors.BraintrustInvalidDataException -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -279,13 +268,10 @@ private constructor( * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times */ - @JsonDeserialize(using = Ids.Deserializer::class) - @JsonSerialize(using = Ids.Serializer::class) class Ids private constructor( private val string: String? = null, private val strings: List? = null, - private val _json: JsonValue? = null, ) { fun string(): Optional = Optional.ofNullable(string) @@ -300,15 +286,12 @@ private constructor( fun asStrings(): List = strings.getOrThrow("strings") - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { string != null -> visitor.visitString(string) strings != null -> visitor.visitStrings(strings) - else -> visitor.unknown(_json) + else -> throw IllegalStateException("Invalid Ids") } - } override fun equals(other: Any?): Boolean { if (this === other) { @@ -324,7 +307,6 @@ private constructor( when { string != null -> "Ids{string=$string}" strings != null -> "Ids{strings=$strings}" - _json != null -> "Ids{_unknown=$_json}" else -> throw IllegalStateException("Invalid Ids") } @@ -341,51 +323,6 @@ private constructor( fun visitString(string: String): T fun visitStrings(strings: List): T - - /** - * Maps an unknown variant of [Ids] to a value of type [T]. - * - * An instance of [Ids] can contain an unknown variant if it was deserialized from data - * that doesn't match any known variant. For example, if the SDK is on an older version - * than the API, then the API may respond with new variants that the SDK is unaware of. - * - * @throws BraintrustInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown Ids: $json") - } - } - - internal class Deserializer : BaseDeserializer(Ids::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Ids { - val json = JsonValue.fromJsonNode(node) - - tryDeserialize(node, jacksonTypeRef())?.let { - return Ids(string = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return Ids(strings = it, _json = json) - } - - return Ids(_json = json) - } - } - - internal class Serializer : BaseSerializer(Ids::class) { - - override fun serialize( - value: Ids, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.string != null -> generator.writeObject(value.string) - value.strings != null -> generator.writeObject(value.strings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Ids") - } - } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListResponse.kt index 4711a9ad..5b96d587 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListResponse.kt @@ -16,6 +16,7 @@ import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.util.Collections import java.util.Objects +import kotlin.jvm.optionals.getOrNull class EnvVarListResponse private constructor( @@ -155,6 +156,23 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (objects.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarObjectType.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarObjectType.kt index b78e5292..db76bd2a 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarObjectType.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarObjectType.kt @@ -101,6 +101,32 @@ class EnvVarObjectType @JsonCreator private constructor(private val value: JsonF fun asString(): String = _value().asString().orElseThrow { BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): EnvVarObjectType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarReplaceParams.kt index 9935a350..484eeaf7 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarReplaceParams.kt @@ -555,11 +555,32 @@ private constructor( name() objectId() - objectType() + objectType().validate() value() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (if (objectId.asKnown().isPresent) 1 else 0) + + (objectType.asKnown().getOrNull()?.validity() ?: 0) + + (if (value.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -674,6 +695,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): ObjectType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarUpdateParams.kt index a8f82c94..1b28c065 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarUpdateParams.kt @@ -439,6 +439,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + (if (value.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt index d8be175f..1b5f81ce 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt @@ -10,6 +10,7 @@ import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params +import com.braintrustdata.api.core.allMaxBy import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow @@ -1717,6 +1718,39 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.validity() ?: 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (scores.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (task.asKnown().getOrNull()?.validity() ?: 0) + + (if (baseExperimentId.asKnown().isPresent) 1 else 0) + + (if (baseExperimentName.asKnown().isPresent) 1 else 0) + + (if (experimentName.asKnown().isPresent) 1 else 0) + + (gitMetadataSettings.asKnown().getOrNull()?.validity() ?: 0) + + (if (isPublic.asKnown().isPresent) 1 else 0) + + (if (maxConcurrency.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (parent.asKnown().getOrNull()?.validity() ?: 0) + + (repoInfo.asKnown().getOrNull()?.validity() ?: 0) + + (if (stream.asKnown().isPresent) 1 else 0) + + (if (timeout.asKnown().isPresent) 1 else 0) + + (if (trialCount.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1774,14 +1808,13 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { datasetId != null -> visitor.visitDatasetId(datasetId) projectDatasetName != null -> visitor.visitProjectDatasetName(projectDatasetName) datasetRows != null -> visitor.visitDatasetRows(datasetRows) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -1808,6 +1841,35 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitDatasetId(datasetId: DatasetId) = datasetId.validity() + + override fun visitProjectDatasetName(projectDatasetName: ProjectDatasetName) = + projectDatasetName.validity() + + override fun visitDatasetRows(datasetRows: DatasetRows) = datasetRows.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1872,20 +1934,31 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): Data { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Data(datasetId = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Data(projectDatasetName = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Data(datasetRows = it, _json = json) - } - - return Data(_json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Data(datasetId = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Data(projectDatasetName = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Data(datasetRows = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with + // all the possible variants (e.g. deserializing from boolean). + 0 -> Data(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the first + // completely valid match, or simply the first match if none are completely + // valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } } } @@ -2081,6 +2154,25 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (datasetId.asKnown().isPresent) 1 else 0) + + (_internalBtql.asKnown().getOrNull()?.validity() ?: 0) + class _InternalBtql @JsonCreator private constructor( @@ -2152,6 +2244,26 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2404,6 +2516,26 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (datasetName.asKnown().isPresent) 1 else 0) + + (if (projectName.asKnown().isPresent) 1 else 0) + + (_internalBtql.asKnown().getOrNull()?.validity() ?: 0) + class _InternalBtql @JsonCreator private constructor( @@ -2475,6 +2607,26 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2653,6 +2805,22 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (data.asKnown().getOrNull()?.size ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2736,8 +2904,8 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { functionId != null -> visitor.visitFunctionId(functionId) projectSlug != null -> visitor.visitProjectSlug(projectSlug) globalFunction != null -> visitor.visitGlobalFunction(globalFunction) @@ -2746,7 +2914,6 @@ private constructor( inlinePrompt != null -> visitor.visitInlinePrompt(inlinePrompt) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -2785,6 +2952,43 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitFunctionId(functionId: FunctionId) = functionId.validity() + + override fun visitProjectSlug(projectSlug: ProjectSlug) = projectSlug.validity() + + override fun visitGlobalFunction(globalFunction: GlobalFunction) = + globalFunction.validity() + + override fun visitPromptSessionId(promptSessionId: PromptSessionId) = + promptSessionId.validity() + + override fun visitInlineCode(inlineCode: InlineCode) = inlineCode.validity() + + override fun visitInlinePrompt(inlinePrompt: InlinePrompt) = + inlinePrompt.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2875,32 +3079,40 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): Score { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Score(functionId = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Score(projectSlug = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Score(globalFunction = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Score(promptSessionId = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Score(inlineCode = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Score(inlinePrompt = it, _json = json) - } - - return Score(_json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Score(functionId = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Score(projectSlug = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Score(globalFunction = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Score(promptSessionId = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Score(inlineCode = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Score(inlinePrompt = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with + // all the possible variants (e.g. deserializing from boolean). + 0 -> Score(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the first + // completely valid match, or simply the first match if none are completely + // valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } } } @@ -3095,6 +3307,25 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (functionId.asKnown().isPresent) 1 else 0) + + (if (version.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3320,6 +3551,26 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (projectName.asKnown().isPresent) 1 else 0) + + (if (slug.asKnown().isPresent) 1 else 0) + + (if (version.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3479,6 +3730,23 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = (if (globalFunction.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3714,6 +3982,26 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (promptSessionFunctionId.asKnown().isPresent) 1 else 0) + + (if (promptSessionId.asKnown().isPresent) 1 else 0) + + (if (version.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3938,6 +4226,26 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (code.asKnown().isPresent) 1 else 0) + + (inlineContext.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + class InlineContext private constructor( private val runtime: JsonField, @@ -4099,11 +4407,30 @@ private constructor( return@apply } - runtime() + runtime().validate() version() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (runtime.asKnown().getOrNull()?.validity() ?: 0) + + (if (version.asKnown().isPresent) 1 else 0) + class Runtime @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -4197,6 +4524,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Runtime = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -4423,6 +4778,25 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (inlinePrompt.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -4506,8 +4880,8 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { functionId != null -> visitor.visitFunctionId(functionId) projectSlug != null -> visitor.visitProjectSlug(projectSlug) globalFunction != null -> visitor.visitGlobalFunction(globalFunction) @@ -4516,7 +4890,6 @@ private constructor( inlinePrompt != null -> visitor.visitInlinePrompt(inlinePrompt) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -4555,6 +4928,43 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitFunctionId(functionId: FunctionId) = functionId.validity() + + override fun visitProjectSlug(projectSlug: ProjectSlug) = projectSlug.validity() + + override fun visitGlobalFunction(globalFunction: GlobalFunction) = + globalFunction.validity() + + override fun visitPromptSessionId(promptSessionId: PromptSessionId) = + promptSessionId.validity() + + override fun visitInlineCode(inlineCode: InlineCode) = inlineCode.validity() + + override fun visitInlinePrompt(inlinePrompt: InlinePrompt) = + inlinePrompt.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -4643,32 +5053,40 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): Task { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Task(functionId = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Task(projectSlug = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Task(globalFunction = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Task(promptSessionId = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Task(inlineCode = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Task(inlinePrompt = it, _json = json) - } - - return Task(_json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Task(functionId = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Task(projectSlug = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Task(globalFunction = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Task(promptSessionId = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Task(inlineCode = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Task(inlinePrompt = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with + // all the possible variants (e.g. deserializing from boolean). + 0 -> Task(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the first + // completely valid match, or simply the first match if none are completely + // valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } } } @@ -4863,6 +5281,25 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (functionId.asKnown().isPresent) 1 else 0) + + (if (version.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -5088,6 +5525,26 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (projectName.asKnown().isPresent) 1 else 0) + + (if (slug.asKnown().isPresent) 1 else 0) + + (if (version.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -5247,6 +5704,23 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = (if (globalFunction.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -5482,6 +5956,26 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (promptSessionFunctionId.asKnown().isPresent) 1 else 0) + + (if (promptSessionId.asKnown().isPresent) 1 else 0) + + (if (version.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -5706,6 +6200,26 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (code.asKnown().isPresent) 1 else 0) + + (inlineContext.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + class InlineContext private constructor( private val runtime: JsonField, @@ -5867,11 +6381,30 @@ private constructor( return@apply } - runtime() + runtime().validate() version() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (runtime.asKnown().getOrNull()?.validity() ?: 0) + + (if (version.asKnown().isPresent) 1 else 0) + class Runtime @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -5965,6 +6498,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Runtime = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -6191,6 +6752,25 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (inlinePrompt.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -6376,11 +6956,30 @@ private constructor( return@apply } - collect() - fields() + collect().validate() + fields().ifPresent { it.forEach { it.validate() } } validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (collect.asKnown().getOrNull()?.validity() ?: 0) + + (fields.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + class Collect @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -6477,6 +7076,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Collect = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -6621,6 +7247,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -6722,6 +7375,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -6767,13 +7438,12 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { spanParentStruct != null -> visitor.visitSpanParentStruct(spanParentStruct) string != null -> visitor.visitString(string) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -6794,6 +7464,33 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitSpanParentStruct(spanParentStruct: SpanParentStruct) = + spanParentStruct.validity() + + override fun visitString(string: String) = 1 + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -6852,15 +7549,28 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): Parent { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Parent(spanParentStruct = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef())?.let { - return Parent(string = it, _json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Parent(spanParentStruct = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Parent(string = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with + // all the possible variants (e.g. deserializing from array). + 0 -> Parent(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the first + // completely valid match, or simply the first match if none are completely + // valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() } - - return Parent(_json = json) } } @@ -7132,12 +7842,33 @@ private constructor( } objectId() - objectType() + objectType().validate() propagatedEvent().ifPresent { it.validate() } rowIds().ifPresent { it.validate() } validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (objectId.asKnown().isPresent) 1 else 0) + + (objectType.asKnown().getOrNull()?.validity() ?: 0) + + (propagatedEvent.asKnown().getOrNull()?.validity() ?: 0) + + (rowIds.asKnown().getOrNull()?.validity() ?: 0) + class ObjectType @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -7236,6 +7967,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): ObjectType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -7322,6 +8080,26 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -7551,6 +8329,26 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (rootSpanId.asKnown().isPresent) 1 else 0) + + (if (spanId.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Experiment.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Experiment.kt index f381c0db..873c1faf 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Experiment.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Experiment.kt @@ -650,6 +650,36 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (public_.asKnown().isPresent) 1 else 0) + + (if (baseExpId.asKnown().isPresent) 1 else 0) + + (if (commit.asKnown().isPresent) 1 else 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (if (datasetId.asKnown().isPresent) 1 else 0) + + (if (datasetVersion.asKnown().isPresent) 1 else 0) + + (if (deletedAt.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (repoInfo.asKnown().getOrNull()?.validity() ?: 0) + + (if (userId.asKnown().isPresent) 1 else 0) + /** User-controlled metadata about the experiment */ class Metadata @JsonCreator @@ -717,6 +747,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentCreateParams.kt index a222a370..521838b0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentCreateParams.kt @@ -1060,6 +1060,33 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (baseExpId.asKnown().isPresent) 1 else 0) + + (if (datasetId.asKnown().isPresent) 1 else 0) + + (if (datasetVersion.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (if (ensureNew.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (public_.asKnown().isPresent) 1 else 0) + + (repoInfo.asKnown().getOrNull()?.validity() ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1145,6 +1172,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentEvent.kt index a8da82d9..64e9d1b8 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentEvent.kt @@ -887,6 +887,38 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (_xactId.asKnown().isPresent) 1 else 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (if (experimentId.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (rootSpanId.asKnown().isPresent) 1 else 0) + + (if (spanId.asKnown().isPresent) 1 else 0) + + (context.asKnown().getOrNull()?.validity() ?: 0) + + (if (isRoot.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (metrics.asKnown().getOrNull()?.validity() ?: 0) + + (origin.asKnown().getOrNull()?.validity() ?: 0) + + (scores.asKnown().getOrNull()?.validity() ?: 0) + + (spanAttributes.asKnown().getOrNull()?.validity() ?: 0) + + (spanParents.asKnown().getOrNull()?.size ?: 0) + + (tags.asKnown().getOrNull()?.size ?: 0) + /** * Context is additional information about the code that produced the experiment event. It is * essentially the textual counterpart to `metrics`. Use the `caller_*` attributes to track the @@ -1115,6 +1147,26 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (callerFilename.asKnown().isPresent) 1 else 0) + + (if (callerFunctionname.asKnown().isPresent) 1 else 0) + + (if (callerLineno.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1249,6 +1301,22 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (if (model.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1658,6 +1726,28 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (completionTokens.asKnown().isPresent) 1 else 0) + + (if (end.asKnown().isPresent) 1 else 0) + + (if (promptTokens.asKnown().isPresent) 1 else 0) + + (if (start.asKnown().isPresent) 1 else 0) + + (if (tokens.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1751,6 +1841,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParams.kt index 4cdb84b8..b3a8bda1 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParams.kt @@ -19,6 +19,7 @@ import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.util.Collections import java.util.Objects +import kotlin.jvm.optionals.getOrNull /** Log feedback for a set of experiment events */ class ExperimentFeedbackParams @@ -402,6 +403,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (feedback.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParams.kt index d306f406..24bd5dfc 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParams.kt @@ -827,6 +827,28 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (cursor.asKnown().isPresent) 1 else 0) + + (if (limit.asKnown().isPresent) 1 else 0) + + (if (maxRootSpanId.asKnown().isPresent) 1 else 0) + + (if (maxXactId.asKnown().isPresent) 1 else 0) + + (if (version.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentInsertParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentInsertParams.kt index 3478b014..de1db1c2 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentInsertParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentInsertParams.kt @@ -19,6 +19,7 @@ import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.util.Collections import java.util.Objects +import kotlin.jvm.optionals.getOrNull /** Insert a set of events into the experiment */ class ExperimentInsertParams @@ -400,6 +401,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (events.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt index 8de7238f..efcde69a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.ExperimentService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -114,6 +115,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt index 9cdda223..07c10b10 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.ExperimentServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -116,6 +117,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListParams.kt index 7a9a3029..29c78e5b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListParams.kt @@ -2,21 +2,10 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.BaseDeserializer -import com.braintrustdata.api.core.BaseSerializer -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.errors.BraintrustInvalidDataException -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -347,13 +336,10 @@ private constructor( * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times */ - @JsonDeserialize(using = Ids.Deserializer::class) - @JsonSerialize(using = Ids.Serializer::class) class Ids private constructor( private val string: String? = null, private val strings: List? = null, - private val _json: JsonValue? = null, ) { fun string(): Optional = Optional.ofNullable(string) @@ -368,15 +354,12 @@ private constructor( fun asStrings(): List = strings.getOrThrow("strings") - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { string != null -> visitor.visitString(string) strings != null -> visitor.visitStrings(strings) - else -> visitor.unknown(_json) + else -> throw IllegalStateException("Invalid Ids") } - } override fun equals(other: Any?): Boolean { if (this === other) { @@ -392,7 +375,6 @@ private constructor( when { string != null -> "Ids{string=$string}" strings != null -> "Ids{strings=$strings}" - _json != null -> "Ids{_unknown=$_json}" else -> throw IllegalStateException("Invalid Ids") } @@ -409,51 +391,6 @@ private constructor( fun visitString(string: String): T fun visitStrings(strings: List): T - - /** - * Maps an unknown variant of [Ids] to a value of type [T]. - * - * An instance of [Ids] can contain an unknown variant if it was deserialized from data - * that doesn't match any known variant. For example, if the SDK is on an older version - * than the API, then the API may respond with new variants that the SDK is unaware of. - * - * @throws BraintrustInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown Ids: $json") - } - } - - internal class Deserializer : BaseDeserializer(Ids::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Ids { - val json = JsonValue.fromJsonNode(node) - - tryDeserialize(node, jacksonTypeRef())?.let { - return Ids(string = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return Ids(strings = it, _json = json) - } - - return Ids(_json = json) - } - } - - internal class Serializer : BaseSerializer(Ids::class) { - - override fun serialize( - value: Ids, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.string != null -> generator.writeObject(value.string) - value.strings != null -> generator.writeObject(value.strings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Ids") - } - } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt index a0bf9a1e..c17bf930 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt @@ -904,6 +904,31 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (baseExpId.asKnown().isPresent) 1 else 0) + + (if (datasetId.asKnown().isPresent) 1 else 0) + + (if (datasetVersion.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (public_.asKnown().isPresent) 1 else 0) + + (repoInfo.asKnown().getOrNull()?.validity() ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -989,6 +1014,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackDatasetItem.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackDatasetItem.kt index a5dea86c..cd797641 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackDatasetItem.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackDatasetItem.kt @@ -301,11 +301,32 @@ private constructor( id() comment() metadata().ifPresent { it.validate() } - source() + source().ifPresent { it.validate() } tags() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (comment.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (source.asKnown().getOrNull()?.validity() ?: 0) + + (tags.asKnown().getOrNull()?.size ?: 0) + /** * A dictionary with additional data about the feedback. If you have a `user_id`, you can log it * here and access it in the Braintrust UI. Note, this metadata does not correspond to the main @@ -377,6 +398,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -488,6 +527,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Source = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackExperimentItem.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackExperimentItem.kt index 193b9801..adc61edb 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackExperimentItem.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackExperimentItem.kt @@ -357,11 +357,33 @@ private constructor( comment() metadata().ifPresent { it.validate() } scores().ifPresent { it.validate() } - source() + source().ifPresent { it.validate() } tags() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (comment.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (scores.asKnown().getOrNull()?.validity() ?: 0) + + (source.asKnown().getOrNull()?.validity() ?: 0) + + (tags.asKnown().getOrNull()?.size ?: 0) + /** * A dictionary with additional data about the feedback. If you have a `user_id`, you can log it * here and access it in the Braintrust UI. Note, this metadata does not correspond to the main @@ -433,6 +455,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -520,6 +560,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -631,6 +689,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Source = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItem.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItem.kt index 875f4110..87e56b04 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItem.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItem.kt @@ -357,11 +357,33 @@ private constructor( comment() metadata().ifPresent { it.validate() } scores().ifPresent { it.validate() } - source() + source().ifPresent { it.validate() } tags() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (comment.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (scores.asKnown().getOrNull()?.validity() ?: 0) + + (source.asKnown().getOrNull()?.validity() ?: 0) + + (tags.asKnown().getOrNull()?.size ?: 0) + /** * A dictionary with additional data about the feedback. If you have a `user_id`, you can log it * here and access it in the Braintrust UI. Note, this metadata does not correspond to the main @@ -433,6 +455,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -520,6 +560,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -631,6 +689,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Source = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackResponseSchema.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackResponseSchema.kt index ed159e98..ef0b762b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackResponseSchema.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackResponseSchema.kt @@ -15,6 +15,7 @@ import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.util.Collections import java.util.Objects +import kotlin.jvm.optionals.getOrNull class FeedbackResponseSchema private constructor( @@ -132,10 +133,25 @@ private constructor( return@apply } - status() + status().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (status.asKnown().getOrNull()?.validity() ?: 0) + class Status @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -217,6 +233,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Status = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchDatasetEventsResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchDatasetEventsResponse.kt index d369727c..62485d5f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchDatasetEventsResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchDatasetEventsResponse.kt @@ -202,6 +202,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (events.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (cursor.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchExperimentEventsResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchExperimentEventsResponse.kt index 6fca6b6e..12f5cc50 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchExperimentEventsResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchExperimentEventsResponse.kt @@ -203,6 +203,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (events.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (cursor.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchProjectLogsEventsResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchProjectLogsEventsResponse.kt index aa41a3d7..5f35d958 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchProjectLogsEventsResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchProjectLogsEventsResponse.kt @@ -206,6 +206,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (events.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (cursor.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Function.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Function.kt index d2ca2dab..c4bc3318 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Function.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Function.kt @@ -9,6 +9,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.allMaxBy import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow @@ -734,7 +735,7 @@ private constructor( id() _xactId() functionData().validate() - logId() + logId().validate() name() orgId() projectId() @@ -742,7 +743,7 @@ private constructor( created() description() functionSchema().ifPresent { it.validate() } - functionType() + functionType().ifPresent { it.validate() } metadata().ifPresent { it.validate() } origin().ifPresent { it.validate() } promptData().ifPresent { it.validate() } @@ -750,6 +751,38 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (_xactId.asKnown().isPresent) 1 else 0) + + (functionData.asKnown().getOrNull()?.validity() ?: 0) + + (logId.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (orgId.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (slug.asKnown().isPresent) 1 else 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (functionSchema.asKnown().getOrNull()?.validity() ?: 0) + + (functionType.asKnown().getOrNull()?.validity() ?: 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (origin.asKnown().getOrNull()?.validity() ?: 0) + + (promptData.asKnown().getOrNull()?.validity() ?: 0) + + (tags.asKnown().getOrNull()?.size ?: 0) + @JsonDeserialize(using = FunctionData.Deserializer::class) @JsonSerialize(using = FunctionData.Serializer::class) class FunctionData @@ -780,14 +813,13 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { prompt != null -> visitor.visitPrompt(prompt) code != null -> visitor.visitCode(code) global != null -> visitor.visitGlobal(global) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -814,6 +846,34 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitPrompt(prompt: Prompt) = prompt.validity() + + override fun visitCode(code: Code) = code.validity() + + override fun visitGlobal(global: Global) = global.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -874,20 +934,31 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): FunctionData { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return FunctionData(prompt = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return FunctionData(code = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return FunctionData(global = it, _json = json) - } - - return FunctionData(_json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + FunctionData(prompt = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + FunctionData(code = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + FunctionData(global = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with + // all the possible variants (e.g. deserializing from boolean). + 0 -> FunctionData(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the first + // completely valid match, or simply the first match if none are completely + // valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } } } @@ -1026,10 +1097,27 @@ private constructor( return@apply } - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = (type.asKnown().getOrNull()?.validity() ?: 0) + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -1114,6 +1202,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1305,10 +1420,29 @@ private constructor( } data().validate() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + @JsonDeserialize(using = Data.Deserializer::class) @JsonSerialize(using = Data.Serializer::class) class Data @@ -1332,13 +1466,12 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { bundle != null -> visitor.visitBundle(bundle) inline != null -> visitor.visitInline(inline) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -1361,6 +1494,32 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitBundle(bundle: Bundle) = bundle.validity() + + override fun visitInline(inline: Inline) = inline.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1416,16 +1575,29 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): Data { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Data(bundle = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Data(inline = it, _json = json) - } - - return Data(_json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Data(bundle = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Data(inline = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. deserializing from + // boolean). + 0 -> Data(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use + // the first completely valid match, or simply the first match if none + // are completely valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } } } @@ -1758,10 +1930,32 @@ private constructor( location().validate() runtimeContext().validate() preview() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (bundleId.asKnown().isPresent) 1 else 0) + + (location.asKnown().getOrNull()?.validity() ?: 0) + + (runtimeContext.asKnown().getOrNull()?.validity() ?: 0) + + (if (preview.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -1850,6 +2044,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2084,10 +2306,30 @@ private constructor( code() runtimeContext().validate() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (code.asKnown().isPresent) 1 else 0) + + (runtimeContext.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + class RuntimeContext private constructor( private val runtime: JsonField, @@ -2259,11 +2501,30 @@ private constructor( return@apply } - runtime() + runtime().validate() version() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (runtime.asKnown().getOrNull()?.validity() ?: 0) + + (if (version.asKnown().isPresent) 1 else 0) + class Runtime @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2363,6 +2624,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Runtime = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in + * this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2482,6 +2771,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2598,6 +2915,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2783,10 +3127,29 @@ private constructor( } name() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2871,6 +3234,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2985,6 +3375,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): LogId = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3090,6 +3507,22 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = 0 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3210,6 +3643,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): FunctionType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3290,6 +3750,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3518,11 +3996,31 @@ private constructor( } objectId() - objectType() + objectType().validate() internal_() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (objectId.asKnown().isPresent) 1 else 0) + + (objectType.asKnown().getOrNull()?.validity() ?: 0) + + (if (internal_.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionCreateParams.kt index e7b6ac47..892a8fb9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionCreateParams.kt @@ -10,6 +10,7 @@ import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params +import com.braintrustdata.api.core.allMaxBy import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow @@ -1038,13 +1039,40 @@ private constructor( slug() description() functionSchema().ifPresent { it.validate() } - functionType() + functionType().ifPresent { it.validate() } origin().ifPresent { it.validate() } promptData().ifPresent { it.validate() } tags() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (functionData.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (slug.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (functionSchema.asKnown().getOrNull()?.validity() ?: 0) + + (functionType.asKnown().getOrNull()?.validity() ?: 0) + + (origin.asKnown().getOrNull()?.validity() ?: 0) + + (promptData.asKnown().getOrNull()?.validity() ?: 0) + + (tags.asKnown().getOrNull()?.size ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1093,14 +1121,13 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { prompt != null -> visitor.visitPrompt(prompt) code != null -> visitor.visitCode(code) global != null -> visitor.visitGlobal(global) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -1127,6 +1154,34 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitPrompt(prompt: Prompt) = prompt.validity() + + override fun visitCode(code: Code) = code.validity() + + override fun visitGlobal(global: Global) = global.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1187,20 +1242,31 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): FunctionData { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return FunctionData(prompt = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return FunctionData(code = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return FunctionData(global = it, _json = json) - } - - return FunctionData(_json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + FunctionData(prompt = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + FunctionData(code = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + FunctionData(global = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with + // all the possible variants (e.g. deserializing from boolean). + 0 -> FunctionData(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the first + // completely valid match, or simply the first match if none are completely + // valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } } } @@ -1339,10 +1405,27 @@ private constructor( return@apply } - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = (type.asKnown().getOrNull()?.validity() ?: 0) + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -1427,6 +1510,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1618,10 +1728,29 @@ private constructor( } data().validate() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + @JsonDeserialize(using = Data.Deserializer::class) @JsonSerialize(using = Data.Serializer::class) class Data @@ -1645,13 +1774,12 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { bundle != null -> visitor.visitBundle(bundle) inline != null -> visitor.visitInline(inline) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -1674,6 +1802,32 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitBundle(bundle: Bundle) = bundle.validity() + + override fun visitInline(inline: Inline) = inline.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1729,16 +1883,29 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): Data { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Data(bundle = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Data(inline = it, _json = json) - } - - return Data(_json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Data(bundle = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Data(inline = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. deserializing from + // boolean). + 0 -> Data(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use + // the first completely valid match, or simply the first match if none + // are completely valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } } } @@ -2071,10 +2238,32 @@ private constructor( location().validate() runtimeContext().validate() preview() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (bundleId.asKnown().isPresent) 1 else 0) + + (location.asKnown().getOrNull()?.validity() ?: 0) + + (runtimeContext.asKnown().getOrNull()?.validity() ?: 0) + + (if (preview.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2163,6 +2352,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2397,10 +2614,30 @@ private constructor( code() runtimeContext().validate() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (code.asKnown().isPresent) 1 else 0) + + (runtimeContext.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + class RuntimeContext private constructor( private val runtime: JsonField, @@ -2572,11 +2809,30 @@ private constructor( return@apply } - runtime() + runtime().validate() version() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (runtime.asKnown().getOrNull()?.validity() ?: 0) + + (if (version.asKnown().isPresent) 1 else 0) + class Runtime @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2676,6 +2932,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Runtime = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in + * this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2795,6 +3079,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2911,6 +3223,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3096,10 +3435,29 @@ private constructor( } name() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -3184,6 +3542,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3308,6 +3693,22 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = 0 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3428,6 +3829,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): FunctionType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3652,11 +4080,31 @@ private constructor( } objectId() - objectType() + objectType().validate() internal_() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (objectId.asKnown().isPresent) 1 else 0) + + (objectType.asKnown().getOrNull()?.validity() ?: 0) + + (if (internal_.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt index 86f08250..6772e006 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt @@ -10,6 +10,7 @@ import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params +import com.braintrustdata.api.core.allMaxBy import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow @@ -816,13 +817,36 @@ private constructor( messages().ifPresent { it.forEach { it.validate() } } metadata().ifPresent { it.validate() } - mode() + mode().ifPresent { it.validate() } parent().ifPresent { it.validate() } stream() version() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (messages.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (mode.asKnown().getOrNull()?.validity() ?: 0) + + (parent.asKnown().getOrNull()?.validity() ?: 0) + + (if (stream.asKnown().isPresent) 1 else 0) + + (if (version.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -892,8 +916,8 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { system != null -> visitor.visitSystem(system) user != null -> visitor.visitUser(user) assistant != null -> visitor.visitAssistant(assistant) @@ -902,7 +926,6 @@ private constructor( fallback != null -> visitor.visitFallback(fallback) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -941,6 +964,40 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitSystem(system: System) = system.validity() + + override fun visitUser(user: User) = user.validity() + + override fun visitAssistant(assistant: Assistant) = assistant.validity() + + override fun visitTool(tool: Tool) = tool.validity() + + override fun visitFunction(function: Function) = function.validity() + + override fun visitFallback(fallback: Fallback) = fallback.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1015,32 +1072,40 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): Message { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Message(system = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Message(user = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Message(assistant = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Message(tool = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Message(function = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Message(fallback = it, _json = json) - } - - return Message(_json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Message(system = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Message(user = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Message(assistant = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Message(tool = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Message(function = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Message(fallback = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with + // all the possible variants (e.g. deserializing from boolean). + 0 -> Message(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the first + // completely valid match, or simply the first match if none are completely + // valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } } } @@ -1245,12 +1310,32 @@ private constructor( return@apply } - role() + role().validate() content() name() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (role.asKnown().getOrNull()?.validity() ?: 0) + + (if (content.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + class Role @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -1335,6 +1420,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Role = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1554,12 +1666,32 @@ private constructor( return@apply } - role() + role().validate() content().ifPresent { it.validate() } name() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (role.asKnown().getOrNull()?.validity() ?: 0) + + (content.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + class Role @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -1644,6 +1776,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Role = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1680,13 +1839,12 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { text != null -> visitor.visitText(text) array != null -> visitor.visitArray(array) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -1707,6 +1865,33 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitText(text: String) = 1 + + override fun visitArray(array: List) = + array.sumOf { it.validity().toInt() } + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1763,17 +1948,31 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): Content { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef())?.let { - return Content(text = it, _json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Content(text = it, _json = json) + }, + tryDeserialize( + node, + jacksonTypeRef>(), + ) + ?.let { Content(array = it, _json = json) }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. deserializing from + // object). + 0 -> Content(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use + // the first completely valid match, or simply the first match if none + // are completely valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() } - tryDeserialize(node, jacksonTypeRef>()) { - it.forEach { it.validate() } - } - ?.let { - return Content(array = it, _json = json) - } - - return Content(_json = json) } } @@ -1817,13 +2016,12 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { text != null -> visitor.visitText(text) image != null -> visitor.visitImage(image) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -1846,6 +2044,34 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitText(text: ChatCompletionContentPartText) = + text.validity() + + override fun visitImage(image: ChatCompletionContentPartImage) = + image.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1913,20 +2139,38 @@ private constructor( ): ChatCompletionContentPart { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { - it.validate() - } - ?.let { - return ChatCompletionContentPart(text = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { - it.validate() - } - ?.let { - return ChatCompletionContentPart(image = it, _json = json) - } - - return ChatCompletionContentPart(_json = json) + val bestMatches = + sequenceOf( + tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + ChatCompletionContentPart(text = it, _json = json) + }, + tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + ChatCompletionContentPart(image = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. deserializing + // from boolean). + 0 -> ChatCompletionContentPart(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then + // use the first completely valid match, or simply the first match + // if none are completely valid. + else -> + bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } } } @@ -2253,7 +2497,7 @@ private constructor( return@apply } - role() + role().validate() content() functionCall().ifPresent { it.validate() } name() @@ -2261,6 +2505,28 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (role.asKnown().getOrNull()?.validity() ?: 0) + + (if (content.asKnown().isPresent) 1 else 0) + + (functionCall.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (toolCalls.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + class Role @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2345,6 +2611,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Role = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2524,6 +2817,25 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (arguments.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2749,12 +3061,32 @@ private constructor( return@apply } - role() + role().validate() content() toolCallId() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (role.asKnown().getOrNull()?.validity() ?: 0) + + (if (content.asKnown().isPresent) 1 else 0) + + (if (toolCallId.asKnown().isPresent) 1 else 0) + class Role @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2839,6 +3171,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Role = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3055,11 +3414,31 @@ private constructor( } name() - role() + role().validate() content() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (role.asKnown().getOrNull()?.validity() ?: 0) + + (if (content.asKnown().isPresent) 1 else 0) + class Role @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -3144,6 +3523,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Role = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3330,11 +3736,30 @@ private constructor( return@apply } - role() + role().validate() content() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (role.asKnown().getOrNull()?.validity() ?: 0) + + (if (content.asKnown().isPresent) 1 else 0) + class Role @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -3419,6 +3844,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Role = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3518,6 +3970,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3623,6 +4093,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Mode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3664,13 +4161,12 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { spanParentStruct != null -> visitor.visitSpanParentStruct(spanParentStruct) string != null -> visitor.visitString(string) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -3691,6 +4187,33 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitSpanParentStruct(spanParentStruct: SpanParentStruct) = + spanParentStruct.validity() + + override fun visitString(string: String) = 1 + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3749,15 +4272,28 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): Parent { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Parent(spanParentStruct = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef())?.let { - return Parent(string = it, _json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Parent(spanParentStruct = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Parent(string = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with + // all the possible variants (e.g. deserializing from array). + 0 -> Parent(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the first + // completely valid match, or simply the first match if none are completely + // valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() } - - return Parent(_json = json) } } @@ -4029,12 +4565,33 @@ private constructor( } objectId() - objectType() + objectType().validate() propagatedEvent().ifPresent { it.validate() } rowIds().ifPresent { it.validate() } validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (objectId.asKnown().isPresent) 1 else 0) + + (objectType.asKnown().getOrNull()?.validity() ?: 0) + + (propagatedEvent.asKnown().getOrNull()?.validity() ?: 0) + + (rowIds.asKnown().getOrNull()?.validity() ?: 0) + class ObjectType @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -4133,6 +4690,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): ObjectType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -4219,6 +4803,26 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -4448,6 +5052,26 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (rootSpanId.asKnown().isPresent) 1 else 0) + + (if (spanId.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeResponse.kt index b590d1f5..924b5b93 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeResponse.kt @@ -4,6 +4,7 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator @@ -81,6 +82,21 @@ private constructor(private val additionalProperties: MutableMap? = null, - private val _json: JsonValue? = null, ) { fun string(): Optional = Optional.ofNullable(string) @@ -405,15 +391,12 @@ private constructor( fun asStrings(): List = strings.getOrThrow("strings") - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { string != null -> visitor.visitString(string) strings != null -> visitor.visitStrings(strings) - else -> visitor.unknown(_json) + else -> throw IllegalStateException("Invalid Ids") } - } override fun equals(other: Any?): Boolean { if (this === other) { @@ -429,7 +412,6 @@ private constructor( when { string != null -> "Ids{string=$string}" strings != null -> "Ids{strings=$strings}" - _json != null -> "Ids{_unknown=$_json}" else -> throw IllegalStateException("Invalid Ids") } @@ -446,51 +428,6 @@ private constructor( fun visitString(string: String): T fun visitStrings(strings: List): T - - /** - * Maps an unknown variant of [Ids] to a value of type [T]. - * - * An instance of [Ids] can contain an unknown variant if it was deserialized from data - * that doesn't match any known variant. For example, if the SDK is on an older version - * than the API, then the API may respond with new variants that the SDK is unaware of. - * - * @throws BraintrustInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown Ids: $json") - } - } - - internal class Deserializer : BaseDeserializer(Ids::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Ids { - val json = JsonValue.fromJsonNode(node) - - tryDeserialize(node, jacksonTypeRef())?.let { - return Ids(string = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return Ids(strings = it, _json = json) - } - - return Ids(_json = json) - } - } - - internal class Serializer : BaseSerializer(Ids::class) { - - override fun serialize( - value: Ids, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.string != null -> generator.writeObject(value.string) - value.strings != null -> generator.writeObject(value.strings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Ids") - } - } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionReplaceParams.kt index f09edae4..54775e95 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionReplaceParams.kt @@ -10,6 +10,7 @@ import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params +import com.braintrustdata.api.core.allMaxBy import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow @@ -1038,13 +1039,40 @@ private constructor( slug() description() functionSchema().ifPresent { it.validate() } - functionType() + functionType().ifPresent { it.validate() } origin().ifPresent { it.validate() } promptData().ifPresent { it.validate() } tags() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (functionData.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (slug.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (functionSchema.asKnown().getOrNull()?.validity() ?: 0) + + (functionType.asKnown().getOrNull()?.validity() ?: 0) + + (origin.asKnown().getOrNull()?.validity() ?: 0) + + (promptData.asKnown().getOrNull()?.validity() ?: 0) + + (tags.asKnown().getOrNull()?.size ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1093,14 +1121,13 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { prompt != null -> visitor.visitPrompt(prompt) code != null -> visitor.visitCode(code) global != null -> visitor.visitGlobal(global) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -1127,6 +1154,34 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitPrompt(prompt: Prompt) = prompt.validity() + + override fun visitCode(code: Code) = code.validity() + + override fun visitGlobal(global: Global) = global.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1187,20 +1242,31 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): FunctionData { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return FunctionData(prompt = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return FunctionData(code = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return FunctionData(global = it, _json = json) - } - - return FunctionData(_json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + FunctionData(prompt = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + FunctionData(code = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + FunctionData(global = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with + // all the possible variants (e.g. deserializing from boolean). + 0 -> FunctionData(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the first + // completely valid match, or simply the first match if none are completely + // valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } } } @@ -1339,10 +1405,27 @@ private constructor( return@apply } - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = (type.asKnown().getOrNull()?.validity() ?: 0) + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -1427,6 +1510,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1618,10 +1728,29 @@ private constructor( } data().validate() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + @JsonDeserialize(using = Data.Deserializer::class) @JsonSerialize(using = Data.Serializer::class) class Data @@ -1645,13 +1774,12 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { bundle != null -> visitor.visitBundle(bundle) inline != null -> visitor.visitInline(inline) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -1674,6 +1802,32 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitBundle(bundle: Bundle) = bundle.validity() + + override fun visitInline(inline: Inline) = inline.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1729,16 +1883,29 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): Data { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Data(bundle = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Data(inline = it, _json = json) - } - - return Data(_json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Data(bundle = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Data(inline = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. deserializing from + // boolean). + 0 -> Data(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use + // the first completely valid match, or simply the first match if none + // are completely valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } } } @@ -2071,10 +2238,32 @@ private constructor( location().validate() runtimeContext().validate() preview() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (bundleId.asKnown().isPresent) 1 else 0) + + (location.asKnown().getOrNull()?.validity() ?: 0) + + (runtimeContext.asKnown().getOrNull()?.validity() ?: 0) + + (if (preview.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2163,6 +2352,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2397,10 +2614,30 @@ private constructor( code() runtimeContext().validate() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (code.asKnown().isPresent) 1 else 0) + + (runtimeContext.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + class RuntimeContext private constructor( private val runtime: JsonField, @@ -2572,11 +2809,30 @@ private constructor( return@apply } - runtime() + runtime().validate() version() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (runtime.asKnown().getOrNull()?.validity() ?: 0) + + (if (version.asKnown().isPresent) 1 else 0) + class Runtime @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2676,6 +2932,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Runtime = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in + * this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2795,6 +3079,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2911,6 +3223,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3096,10 +3435,29 @@ private constructor( } name() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -3184,6 +3542,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3308,6 +3693,22 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = 0 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3428,6 +3829,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): FunctionType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3652,11 +4080,31 @@ private constructor( } objectId() - objectType() + objectType().validate() internal_() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (objectId.asKnown().isPresent) 1 else 0) + + (objectType.asKnown().getOrNull()?.validity() ?: 0) + + (if (internal_.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt index 280402c1..dab7e59e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt @@ -10,6 +10,7 @@ import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params +import com.braintrustdata.api.core.allMaxBy import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow @@ -706,6 +707,28 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (description.asKnown().isPresent) 1 else 0) + + (functionData.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (promptData.asKnown().getOrNull()?.validity() ?: 0) + + (tags.asKnown().getOrNull()?.size ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -754,14 +777,13 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { prompt != null -> visitor.visitPrompt(prompt) code != null -> visitor.visitCode(code) global != null -> visitor.visitGlobal(global) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -788,6 +810,34 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitPrompt(prompt: Prompt) = prompt.validity() + + override fun visitCode(code: Code) = code.validity() + + override fun visitGlobal(global: Global) = global.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -848,20 +898,31 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): FunctionData { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return FunctionData(prompt = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return FunctionData(code = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return FunctionData(global = it, _json = json) - } - - return FunctionData(_json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + FunctionData(prompt = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + FunctionData(code = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + FunctionData(global = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with + // all the possible variants (e.g. deserializing from boolean). + 0 -> FunctionData(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the first + // completely valid match, or simply the first match if none are completely + // valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } } } @@ -1000,10 +1061,27 @@ private constructor( return@apply } - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = (type.asKnown().getOrNull()?.validity() ?: 0) + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -1088,6 +1166,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1279,10 +1384,29 @@ private constructor( } data().validate() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + @JsonDeserialize(using = Data.Deserializer::class) @JsonSerialize(using = Data.Serializer::class) class Data @@ -1306,13 +1430,12 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { bundle != null -> visitor.visitBundle(bundle) inline != null -> visitor.visitInline(inline) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -1335,6 +1458,32 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitBundle(bundle: Bundle) = bundle.validity() + + override fun visitInline(inline: Inline) = inline.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1390,16 +1539,29 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): Data { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Data(bundle = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Data(inline = it, _json = json) - } - - return Data(_json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Data(bundle = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Data(inline = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. deserializing from + // boolean). + 0 -> Data(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use + // the first completely valid match, or simply the first match if none + // are completely valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } } } @@ -1732,10 +1894,32 @@ private constructor( location().validate() runtimeContext().validate() preview() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (bundleId.asKnown().isPresent) 1 else 0) + + (location.asKnown().getOrNull()?.validity() ?: 0) + + (runtimeContext.asKnown().getOrNull()?.validity() ?: 0) + + (if (preview.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -1824,6 +2008,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2058,10 +2270,30 @@ private constructor( code() runtimeContext().validate() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (code.asKnown().isPresent) 1 else 0) + + (runtimeContext.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + class RuntimeContext private constructor( private val runtime: JsonField, @@ -2233,11 +2465,30 @@ private constructor( return@apply } - runtime() + runtime().validate() version() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (runtime.asKnown().getOrNull()?.validity() ?: 0) + + (if (version.asKnown().isPresent) 1 else 0) + class Runtime @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2337,6 +2588,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Runtime = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in + * this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2456,6 +2735,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2572,6 +2879,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2757,10 +3091,29 @@ private constructor( } name() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2845,6 +3198,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Group.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Group.kt index a81249f1..f8ac8b97 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Group.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Group.kt @@ -506,6 +506,31 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (orgId.asKnown().isPresent) 1 else 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (if (deletedAt.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (memberGroups.asKnown().getOrNull()?.size ?: 0) + + (memberUsers.asKnown().getOrNull()?.size ?: 0) + + (if (userId.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupCreateParams.kt index 410b148e..bbcf346b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupCreateParams.kt @@ -721,6 +721,28 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (memberGroups.asKnown().getOrNull()?.size ?: 0) + + (memberUsers.asKnown().getOrNull()?.size ?: 0) + + (if (orgName.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt index bf5f8743..25297bb8 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.GroupService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -111,6 +112,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt index 8ddc2ba7..4bc457e6 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.GroupServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -113,6 +114,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListParams.kt index 9ab47c5c..eb8cc72c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListParams.kt @@ -2,21 +2,10 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.BaseDeserializer -import com.braintrustdata.api.core.BaseSerializer -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.errors.BraintrustInvalidDataException -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -318,13 +307,10 @@ private constructor( * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times */ - @JsonDeserialize(using = Ids.Deserializer::class) - @JsonSerialize(using = Ids.Serializer::class) class Ids private constructor( private val string: String? = null, private val strings: List? = null, - private val _json: JsonValue? = null, ) { fun string(): Optional = Optional.ofNullable(string) @@ -339,15 +325,12 @@ private constructor( fun asStrings(): List = strings.getOrThrow("strings") - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { string != null -> visitor.visitString(string) strings != null -> visitor.visitStrings(strings) - else -> visitor.unknown(_json) + else -> throw IllegalStateException("Invalid Ids") } - } override fun equals(other: Any?): Boolean { if (this === other) { @@ -363,7 +346,6 @@ private constructor( when { string != null -> "Ids{string=$string}" strings != null -> "Ids{strings=$strings}" - _json != null -> "Ids{_unknown=$_json}" else -> throw IllegalStateException("Invalid Ids") } @@ -380,51 +362,6 @@ private constructor( fun visitString(string: String): T fun visitStrings(strings: List): T - - /** - * Maps an unknown variant of [Ids] to a value of type [T]. - * - * An instance of [Ids] can contain an unknown variant if it was deserialized from data - * that doesn't match any known variant. For example, if the SDK is on an older version - * than the API, then the API may respond with new variants that the SDK is unaware of. - * - * @throws BraintrustInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown Ids: $json") - } - } - - internal class Deserializer : BaseDeserializer(Ids::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Ids { - val json = JsonValue.fromJsonNode(node) - - tryDeserialize(node, jacksonTypeRef())?.let { - return Ids(string = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return Ids(strings = it, _json = json) - } - - return Ids(_json = json) - } - } - - internal class Serializer : BaseSerializer(Ids::class) { - - override fun serialize( - value: Ids, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.string != null -> generator.writeObject(value.string) - value.strings != null -> generator.writeObject(value.strings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Ids") - } - } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupReplaceParams.kt index 4ee6109f..24c23202 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupReplaceParams.kt @@ -721,6 +721,28 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (memberGroups.asKnown().getOrNull()?.size ?: 0) + + (memberUsers.asKnown().getOrNull()?.size ?: 0) + + (if (orgName.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupUpdateParams.kt index 5e1672d5..852acd26 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupUpdateParams.kt @@ -866,6 +866,29 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (addMemberGroups.asKnown().getOrNull()?.size ?: 0) + + (addMemberUsers.asKnown().getOrNull()?.size ?: 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (removeMemberGroups.asKnown().getOrNull()?.size ?: 0) + + (removeMemberUsers.asKnown().getOrNull()?.size ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertDatasetEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertDatasetEvent.kt index 5c9c0ead..d8135d03 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertDatasetEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertDatasetEvent.kt @@ -832,6 +832,34 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (_isMerge.asKnown().isPresent) 1 else 0) + + (_mergePaths.asKnown().getOrNull()?.sumOf { it.size.toInt() } ?: 0) + + (if (_objectDelete.asKnown().isPresent) 1 else 0) + + (if (_parentId.asKnown().isPresent) 1 else 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (origin.asKnown().getOrNull()?.validity() ?: 0) + + (if (rootSpanId.asKnown().isPresent) 1 else 0) + + (if (spanId.asKnown().isPresent) 1 else 0) + + (spanParents.asKnown().getOrNull()?.size ?: 0) + + (tags.asKnown().getOrNull()?.size ?: 0) + /** * A dictionary with additional data about the test example, model outputs, or just about * anything else that's relevant, that you can use to help find and analyze examples later. For @@ -948,6 +976,22 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (if (model.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertEventsResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertEventsResponse.kt index fb891b77..becc87ae 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertEventsResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertEventsResponse.kt @@ -16,6 +16,7 @@ import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.util.Collections import java.util.Objects +import kotlin.jvm.optionals.getOrNull class InsertEventsResponse private constructor( @@ -158,6 +159,21 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (rowIds.asKnown().getOrNull()?.size ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertExperimentEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertExperimentEvent.kt index e335fd4c..95532feb 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertExperimentEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertExperimentEvent.kt @@ -1064,6 +1064,38 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (_isMerge.asKnown().isPresent) 1 else 0) + + (_mergePaths.asKnown().getOrNull()?.sumOf { it.size.toInt() } ?: 0) + + (if (_objectDelete.asKnown().isPresent) 1 else 0) + + (if (_parentId.asKnown().isPresent) 1 else 0) + + (context.asKnown().getOrNull()?.validity() ?: 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (metrics.asKnown().getOrNull()?.validity() ?: 0) + + (origin.asKnown().getOrNull()?.validity() ?: 0) + + (if (rootSpanId.asKnown().isPresent) 1 else 0) + + (scores.asKnown().getOrNull()?.validity() ?: 0) + + (spanAttributes.asKnown().getOrNull()?.validity() ?: 0) + + (if (spanId.asKnown().isPresent) 1 else 0) + + (spanParents.asKnown().getOrNull()?.size ?: 0) + + (tags.asKnown().getOrNull()?.size ?: 0) + /** * Context is additional information about the code that produced the experiment event. It is * essentially the textual counterpart to `metrics`. Use the `caller_*` attributes to track the @@ -1292,6 +1324,26 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (callerFilename.asKnown().isPresent) 1 else 0) + + (if (callerFunctionname.asKnown().isPresent) 1 else 0) + + (if (callerLineno.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1426,6 +1478,22 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (if (model.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1835,6 +1903,28 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (completionTokens.asKnown().isPresent) 1 else 0) + + (if (end.asKnown().isPresent) 1 else 0) + + (if (promptTokens.asKnown().isPresent) 1 else 0) + + (if (start.asKnown().isPresent) 1 else 0) + + (if (tokens.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1928,6 +2018,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertProjectLogsEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertProjectLogsEvent.kt index c2e77ee5..e8b56179 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertProjectLogsEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertProjectLogsEvent.kt @@ -1056,6 +1056,38 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (_isMerge.asKnown().isPresent) 1 else 0) + + (_mergePaths.asKnown().getOrNull()?.sumOf { it.size.toInt() } ?: 0) + + (if (_objectDelete.asKnown().isPresent) 1 else 0) + + (if (_parentId.asKnown().isPresent) 1 else 0) + + (context.asKnown().getOrNull()?.validity() ?: 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (metrics.asKnown().getOrNull()?.validity() ?: 0) + + (origin.asKnown().getOrNull()?.validity() ?: 0) + + (if (rootSpanId.asKnown().isPresent) 1 else 0) + + (scores.asKnown().getOrNull()?.validity() ?: 0) + + (spanAttributes.asKnown().getOrNull()?.validity() ?: 0) + + (if (spanId.asKnown().isPresent) 1 else 0) + + (spanParents.asKnown().getOrNull()?.size ?: 0) + + (tags.asKnown().getOrNull()?.size ?: 0) + /** * Context is additional information about the code that produced the project logs event. It is * essentially the textual counterpart to `metrics`. Use the `caller_*` attributes to track the @@ -1284,6 +1316,26 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (callerFilename.asKnown().isPresent) 1 else 0) + + (if (callerFunctionname.asKnown().isPresent) 1 else 0) + + (if (callerLineno.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1418,6 +1470,22 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (if (model.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1827,6 +1895,28 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (completionTokens.asKnown().isPresent) 1 else 0) + + (if (end.asKnown().isPresent) 1 else 0) + + (if (promptTokens.asKnown().isPresent) 1 else 0) + + (if (start.asKnown().isPresent) 1 else 0) + + (if (tokens.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1920,6 +2010,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/MetricSummary.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/MetricSummary.kt index 55945097..2eb6fef9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/MetricSummary.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/MetricSummary.kt @@ -316,6 +316,28 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (improvements.asKnown().isPresent) 1 else 0) + + (if (metric.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (regressions.asKnown().isPresent) 1 else 0) + + (if (unit.asKnown().isPresent) 1 else 0) + + (if (diff.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ObjectReference.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ObjectReference.kt index aed4f93e..454b2d28 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ObjectReference.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ObjectReference.kt @@ -279,11 +279,32 @@ private constructor( id() _xactId() objectId() - objectType() + objectType().validate() created() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (_xactId.asKnown().isPresent) 1 else 0) + + (if (objectId.asKnown().isPresent) 1 else 0) + + (objectType.asKnown().getOrNull()?.validity() ?: 0) + + (if (created.asKnown().isPresent) 1 else 0) + /** Type of the object the event is originating from. */ class ObjectType @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -398,6 +419,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): ObjectType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OnlineScoreConfig.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OnlineScoreConfig.kt index 7507d9e5..58e76cae 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OnlineScoreConfig.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OnlineScoreConfig.kt @@ -9,6 +9,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.allMaxBy import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow @@ -327,6 +328,26 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (samplingRate.asKnown().isPresent) 1 else 0) + + (scorers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (applyToRootSpan.asKnown().isPresent) 1 else 0) + + (applyToSpanNames.asKnown().getOrNull()?.size ?: 0) + @JsonDeserialize(using = Scorer.Deserializer::class) @JsonSerialize(using = Scorer.Serializer::class) class Scorer @@ -350,13 +371,12 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { function != null -> visitor.visitFunction(function) global != null -> visitor.visitGlobal(global) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -379,6 +399,32 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitFunction(function: Function) = function.validity() + + override fun visitGlobal(global: Global) = global.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -431,16 +477,28 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): Scorer { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Scorer(function = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Scorer(global = it, _json = json) - } - - return Scorer(_json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Scorer(function = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Scorer(global = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with + // all the possible variants (e.g. deserializing from boolean). + 0 -> Scorer(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the first + // completely valid match, or simply the first match if none are completely + // valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } } } @@ -614,10 +672,29 @@ private constructor( } id() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -702,6 +779,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -887,10 +991,29 @@ private constructor( } name() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -975,6 +1098,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Organization.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Organization.kt index 0c3299cf..63cfbf92 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Organization.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Organization.kt @@ -364,6 +364,29 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (apiUrl.asKnown().isPresent) 1 else 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (if (isUniversalApi.asKnown().isPresent) 1 else 0) + + (if (proxyUrl.asKnown().isPresent) 1 else 0) + + (if (realtimeUrl.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt index f2c435ae..91510104 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.OrganizationService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -114,6 +115,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt index a73956de..c17537ef 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.OrganizationServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -116,6 +117,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListParams.kt index 8a22272f..af6f46c8 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListParams.kt @@ -2,21 +2,10 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.BaseDeserializer -import com.braintrustdata.api.core.BaseSerializer -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.errors.BraintrustInvalidDataException -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -304,13 +293,10 @@ private constructor( * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times */ - @JsonDeserialize(using = Ids.Deserializer::class) - @JsonSerialize(using = Ids.Serializer::class) class Ids private constructor( private val string: String? = null, private val strings: List? = null, - private val _json: JsonValue? = null, ) { fun string(): Optional = Optional.ofNullable(string) @@ -325,15 +311,12 @@ private constructor( fun asStrings(): List = strings.getOrThrow("strings") - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { string != null -> visitor.visitString(string) strings != null -> visitor.visitStrings(strings) - else -> visitor.unknown(_json) + else -> throw IllegalStateException("Invalid Ids") } - } override fun equals(other: Any?): Boolean { if (this === other) { @@ -349,7 +332,6 @@ private constructor( when { string != null -> "Ids{string=$string}" strings != null -> "Ids{strings=$strings}" - _json != null -> "Ids{_unknown=$_json}" else -> throw IllegalStateException("Invalid Ids") } @@ -366,51 +348,6 @@ private constructor( fun visitString(string: String): T fun visitStrings(strings: List): T - - /** - * Maps an unknown variant of [Ids] to a value of type [T]. - * - * An instance of [Ids] can contain an unknown variant if it was deserialized from data - * that doesn't match any known variant. For example, if the SDK is on an older version - * than the API, then the API may respond with new variants that the SDK is unaware of. - * - * @throws BraintrustInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown Ids: $json") - } - } - - internal class Deserializer : BaseDeserializer(Ids::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Ids { - val json = JsonValue.fromJsonNode(node) - - tryDeserialize(node, jacksonTypeRef())?.let { - return Ids(string = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return Ids(strings = it, _json = json) - } - - return Ids(_json = json) - } - } - - internal class Serializer : BaseSerializer(Ids::class) { - - override fun serialize( - value: Ids, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.string != null -> generator.writeObject(value.string) - value.strings != null -> generator.writeObject(value.strings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Ids") - } - } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationMemberUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationMemberUpdateParams.kt index 471b4675..2e350e16 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationMemberUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationMemberUpdateParams.kt @@ -579,6 +579,27 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (inviteUsers.asKnown().getOrNull()?.validity() ?: 0) + + (if (orgId.asKnown().isPresent) 1 else 0) + + (if (orgName.asKnown().isPresent) 1 else 0) + + (removeUsers.asKnown().getOrNull()?.validity() ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1023,6 +1044,30 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (emails.asKnown().getOrNull()?.size ?: 0) + + (if (groupId.asKnown().isPresent) 1 else 0) + + (groupIds.asKnown().getOrNull()?.size ?: 0) + + (if (groupName.asKnown().isPresent) 1 else 0) + + (groupNames.asKnown().getOrNull()?.size ?: 0) + + (ids.asKnown().getOrNull()?.size ?: 0) + + (if (sendInviteEmails.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1218,6 +1263,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (emails.asKnown().getOrNull()?.size ?: 0) + (ids.asKnown().getOrNull()?.size ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationUpdateParams.kt index 3a60e7eb..2112877a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationUpdateParams.kt @@ -642,6 +642,28 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (apiUrl.asKnown().isPresent) 1 else 0) + + (if (isUniversalApi.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (proxyUrl.asKnown().isPresent) 1 else 0) + + (if (realtimeUrl.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PatchOrganizationMembersOutput.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PatchOrganizationMembersOutput.kt index 98a4db87..b767f148 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PatchOrganizationMembersOutput.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PatchOrganizationMembersOutput.kt @@ -218,11 +218,30 @@ private constructor( } orgId() - status() + status().validate() sendEmailError() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (orgId.asKnown().isPresent) 1 else 0) + + (status.asKnown().getOrNull()?.validity() ?: 0) + + (if (sendEmailError.asKnown().isPresent) 1 else 0) + class Status @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -304,6 +323,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Status = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Permission.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Permission.kt index 7b884f8d..7e4cb415 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Permission.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Permission.kt @@ -132,6 +132,32 @@ class Permission @JsonCreator private constructor(private val value: JsonField? = null, - private val _json: JsonValue? = null, ) { fun string(): Optional = Optional.ofNullable(string) @@ -339,15 +325,12 @@ private constructor( fun asStrings(): List = strings.getOrThrow("strings") - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { string != null -> visitor.visitString(string) strings != null -> visitor.visitStrings(strings) - else -> visitor.unknown(_json) + else -> throw IllegalStateException("Invalid Ids") } - } override fun equals(other: Any?): Boolean { if (this === other) { @@ -363,7 +346,6 @@ private constructor( when { string != null -> "Ids{string=$string}" strings != null -> "Ids{strings=$strings}" - _json != null -> "Ids{_unknown=$_json}" else -> throw IllegalStateException("Invalid Ids") } @@ -380,51 +362,6 @@ private constructor( fun visitString(string: String): T fun visitStrings(strings: List): T - - /** - * Maps an unknown variant of [Ids] to a value of type [T]. - * - * An instance of [Ids] can contain an unknown variant if it was deserialized from data - * that doesn't match any known variant. For example, if the SDK is on an older version - * than the API, then the API may respond with new variants that the SDK is unaware of. - * - * @throws BraintrustInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown Ids: $json") - } - } - - internal class Deserializer : BaseDeserializer(Ids::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Ids { - val json = JsonValue.fromJsonNode(node) - - tryDeserialize(node, jacksonTypeRef())?.let { - return Ids(string = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return Ids(strings = it, _json = json) - } - - return Ids(_json = json) - } - } - - internal class Serializer : BaseSerializer(Ids::class) { - - override fun serialize( - value: Ids, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.string != null -> generator.writeObject(value.string) - value.strings != null -> generator.writeObject(value.strings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Ids") - } - } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParams.kt index 79ab6c63..14c2dfe1 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParams.kt @@ -19,6 +19,7 @@ import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.util.Collections import java.util.Objects +import kotlin.jvm.optionals.getOrNull /** Log feedback for a set of project logs events */ class ProjectLogFeedbackParams @@ -402,6 +403,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (feedback.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParams.kt index ac207b10..dd5bc517 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParams.kt @@ -827,6 +827,28 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (cursor.asKnown().isPresent) 1 else 0) + + (if (limit.asKnown().isPresent) 1 else 0) + + (if (maxRootSpanId.asKnown().isPresent) 1 else 0) + + (if (maxXactId.asKnown().isPresent) 1 else 0) + + (if (version.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogInsertParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogInsertParams.kt index aba94683..285b253b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogInsertParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogInsertParams.kt @@ -19,6 +19,7 @@ import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.util.Collections import java.util.Objects +import kotlin.jvm.optionals.getOrNull /** Insert a set of events into the project logs */ class ProjectLogInsertParams @@ -400,6 +401,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (events.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogsEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogsEvent.kt index 5d406343..59c8be8e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogsEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogsEvent.kt @@ -892,7 +892,7 @@ private constructor( id() _xactId() created() - logId() + logId().validate() orgId() projectId() rootSpanId() @@ -909,6 +909,39 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (_xactId.asKnown().isPresent) 1 else 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (logId.asKnown().getOrNull()?.validity() ?: 0) + + (if (orgId.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (rootSpanId.asKnown().isPresent) 1 else 0) + + (if (spanId.asKnown().isPresent) 1 else 0) + + (context.asKnown().getOrNull()?.validity() ?: 0) + + (if (isRoot.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (metrics.asKnown().getOrNull()?.validity() ?: 0) + + (origin.asKnown().getOrNull()?.validity() ?: 0) + + (scores.asKnown().getOrNull()?.validity() ?: 0) + + (spanAttributes.asKnown().getOrNull()?.validity() ?: 0) + + (spanParents.asKnown().getOrNull()?.size ?: 0) + + (tags.asKnown().getOrNull()?.size ?: 0) + /** A literal 'g' which identifies the log as a project log */ class LogId @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -991,6 +1024,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): LogId = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1232,6 +1292,26 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (callerFilename.asKnown().isPresent) 1 else 0) + + (if (callerFunctionname.asKnown().isPresent) 1 else 0) + + (if (callerLineno.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1366,6 +1446,22 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (if (model.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1775,6 +1871,28 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (completionTokens.asKnown().isPresent) 1 else 0) + + (if (end.asKnown().isPresent) 1 else 0) + + (if (promptTokens.asKnown().isPresent) 1 else 0) + + (if (start.asKnown().isPresent) 1 else 0) + + (if (tokens.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1868,6 +1986,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScore.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScore.kt index 41a42006..36f2a4fc 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScore.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScore.kt @@ -8,6 +8,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.allMaxBy import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.toImmutable @@ -492,7 +493,7 @@ private constructor( id() name() projectId() - scoreType() + scoreType().validate() userId() categories().ifPresent { it.validate() } config().ifPresent { it.validate() } @@ -502,6 +503,32 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (scoreType.asKnown().getOrNull()?.validity() ?: 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + (categories.asKnown().getOrNull()?.validity() ?: 0) + + (config.asKnown().getOrNull()?.validity() ?: 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (if (position.asKnown().isPresent) 1 else 0) + /** For categorical-type project scores, the list of all categories */ @JsonDeserialize(using = Categories.Deserializer::class) @JsonSerialize(using = Categories.Serializer::class) @@ -539,14 +566,13 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { categorical != null -> visitor.visitCategorical(categorical) weighted != null -> visitor.visitWeighted(weighted) minimum != null -> visitor.visitMinimum(minimum) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -571,6 +597,35 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitCategorical(categorical: List) = + categorical.sumOf { it.validity().toInt() } + + override fun visitWeighted(weighted: Weighted) = weighted.validity() + + override fun visitMinimum(minimum: List) = minimum.size + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -638,21 +693,30 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): Categories { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef>()) { - it.forEach { it.validate() } - } - ?.let { - return Categories(categorical = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Categories(weighted = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return Categories(minimum = it, _json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Categories(weighted = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef>()) + ?.let { Categories(categorical = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef>())?.let { + Categories(minimum = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with + // all the possible variants (e.g. deserializing from boolean). + 0 -> Categories(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the first + // completely valid match, or simply the first match if none are completely + // valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() } - - return Categories(_json = json) } } @@ -743,6 +807,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCategory.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCategory.kt index 234a71f3..92dcb461 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCategory.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCategory.kt @@ -173,6 +173,23 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + (if (value.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreConfig.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreConfig.kt index 6f32492f..79716066 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreConfig.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreConfig.kt @@ -209,6 +209,25 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (destination.asKnown().isPresent) 1 else 0) + + (if (multiSelect.asKnown().isPresent) 1 else 0) + + (online.asKnown().getOrNull()?.validity() ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParams.kt index f626e896..676216db 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParams.kt @@ -9,6 +9,7 @@ import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params +import com.braintrustdata.api.core.allMaxBy import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers @@ -734,13 +735,36 @@ private constructor( name() projectId() - scoreType() + scoreType().validate() categories().ifPresent { it.validate() } config().ifPresent { it.validate() } description() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (scoreType.asKnown().getOrNull()?.validity() ?: 0) + + (categories.asKnown().getOrNull()?.validity() ?: 0) + + (config.asKnown().getOrNull()?.validity() ?: 0) + + (if (description.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -796,14 +820,13 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { categorical != null -> visitor.visitCategorical(categorical) weighted != null -> visitor.visitWeighted(weighted) minimum != null -> visitor.visitMinimum(minimum) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -828,6 +851,35 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitCategorical(categorical: List) = + categorical.sumOf { it.validity().toInt() } + + override fun visitWeighted(weighted: Weighted) = weighted.validity() + + override fun visitMinimum(minimum: List) = minimum.size + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -895,21 +947,30 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): Categories { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef>()) { - it.forEach { it.validate() } - } - ?.let { - return Categories(categorical = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Categories(weighted = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return Categories(minimum = it, _json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Categories(weighted = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef>()) + ?.let { Categories(categorical = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef>())?.let { + Categories(minimum = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with + // all the possible variants (e.g. deserializing from boolean). + 0 -> Categories(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the first + // completely valid match, or simply the first match if none are completely + // valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() } - - return Categories(_json = json) } } @@ -1000,6 +1061,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt index aee346bb..73ffa350 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.ProjectScoreService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -114,6 +115,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt index 24fb91c8..62dc8535 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.ProjectScoreServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -116,6 +117,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListParams.kt index e4d1432f..0b850233 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListParams.kt @@ -2,21 +2,10 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.BaseDeserializer -import com.braintrustdata.api.core.BaseSerializer -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.errors.BraintrustInvalidDataException -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -384,13 +373,10 @@ private constructor( * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times */ - @JsonDeserialize(using = Ids.Deserializer::class) - @JsonSerialize(using = Ids.Serializer::class) class Ids private constructor( private val string: String? = null, private val strings: List? = null, - private val _json: JsonValue? = null, ) { fun string(): Optional = Optional.ofNullable(string) @@ -405,15 +391,12 @@ private constructor( fun asStrings(): List = strings.getOrThrow("strings") - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { string != null -> visitor.visitString(string) strings != null -> visitor.visitStrings(strings) - else -> visitor.unknown(_json) + else -> throw IllegalStateException("Invalid Ids") } - } override fun equals(other: Any?): Boolean { if (this === other) { @@ -429,7 +412,6 @@ private constructor( when { string != null -> "Ids{string=$string}" strings != null -> "Ids{strings=$strings}" - _json != null -> "Ids{_unknown=$_json}" else -> throw IllegalStateException("Invalid Ids") } @@ -446,62 +428,14 @@ private constructor( fun visitString(string: String): T fun visitStrings(strings: List): T - - /** - * Maps an unknown variant of [Ids] to a value of type [T]. - * - * An instance of [Ids] can contain an unknown variant if it was deserialized from data - * that doesn't match any known variant. For example, if the SDK is on an older version - * than the API, then the API may respond with new variants that the SDK is unaware of. - * - * @throws BraintrustInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown Ids: $json") - } - } - - internal class Deserializer : BaseDeserializer(Ids::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Ids { - val json = JsonValue.fromJsonNode(node) - - tryDeserialize(node, jacksonTypeRef())?.let { - return Ids(string = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return Ids(strings = it, _json = json) - } - - return Ids(_json = json) - } - } - - internal class Serializer : BaseSerializer(Ids::class) { - - override fun serialize( - value: Ids, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.string != null -> generator.writeObject(value.string) - value.strings != null -> generator.writeObject(value.strings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Ids") - } - } } } /** The type of the configured score */ - @JsonDeserialize(using = ScoreType.Deserializer::class) - @JsonSerialize(using = ScoreType.Serializer::class) class ScoreType private constructor( private val project: ProjectScoreType? = null, private val projectScoreTypes: List? = null, - private val _json: JsonValue? = null, ) { /** The type of the configured score */ @@ -522,15 +456,12 @@ private constructor( fun asProjectScoreTypes(): List = projectScoreTypes.getOrThrow("projectScoreTypes") - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { project != null -> visitor.visitProject(project) projectScoreTypes != null -> visitor.visitProjectScoreTypes(projectScoreTypes) - else -> visitor.unknown(_json) + else -> throw IllegalStateException("Invalid ScoreType") } - } override fun equals(other: Any?): Boolean { if (this === other) { @@ -546,7 +477,6 @@ private constructor( when { project != null -> "ScoreType{project=$project}" projectScoreTypes != null -> "ScoreType{projectScoreTypes=$projectScoreTypes}" - _json != null -> "ScoreType{_unknown=$_json}" else -> throw IllegalStateException("Invalid ScoreType") } @@ -571,53 +501,6 @@ private constructor( /** The type of the configured score */ fun visitProjectScoreTypes(projectScoreTypes: List): T - - /** - * Maps an unknown variant of [ScoreType] to a value of type [T]. - * - * An instance of [ScoreType] can contain an unknown variant if it was deserialized from - * data that doesn't match any known variant. For example, if the SDK is on an older - * version than the API, then the API may respond with new variants that the SDK is - * unaware of. - * - * @throws BraintrustInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown ScoreType: $json") - } - } - - internal class Deserializer : BaseDeserializer(ScoreType::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ScoreType { - val json = JsonValue.fromJsonNode(node) - - tryDeserialize(node, jacksonTypeRef())?.let { - return ScoreType(project = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return ScoreType(projectScoreTypes = it, _json = json) - } - - return ScoreType(_json = json) - } - } - - internal class Serializer : BaseSerializer(ScoreType::class) { - - override fun serialize( - value: ScoreType, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.project != null -> generator.writeObject(value.project) - value.projectScoreTypes != null -> - generator.writeObject(value.projectScoreTypes) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ScoreType") - } - } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParams.kt index acfc9aa7..5351084a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParams.kt @@ -9,6 +9,7 @@ import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params +import com.braintrustdata.api.core.allMaxBy import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers @@ -735,13 +736,36 @@ private constructor( name() projectId() - scoreType() + scoreType().validate() categories().ifPresent { it.validate() } config().ifPresent { it.validate() } description() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (scoreType.asKnown().getOrNull()?.validity() ?: 0) + + (categories.asKnown().getOrNull()?.validity() ?: 0) + + (config.asKnown().getOrNull()?.validity() ?: 0) + + (if (description.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -797,14 +821,13 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { categorical != null -> visitor.visitCategorical(categorical) weighted != null -> visitor.visitWeighted(weighted) minimum != null -> visitor.visitMinimum(minimum) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -829,6 +852,35 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitCategorical(categorical: List) = + categorical.sumOf { it.validity().toInt() } + + override fun visitWeighted(weighted: Weighted) = weighted.validity() + + override fun visitMinimum(minimum: List) = minimum.size + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -896,21 +948,30 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): Categories { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef>()) { - it.forEach { it.validate() } - } - ?.let { - return Categories(categorical = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Categories(weighted = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return Categories(minimum = it, _json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Categories(weighted = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef>()) + ?.let { Categories(categorical = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef>())?.let { + Categories(minimum = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with + // all the possible variants (e.g. deserializing from boolean). + 0 -> Categories(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the first + // completely valid match, or simply the first match if none are completely + // valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() } - - return Categories(_json = json) } } @@ -1001,6 +1062,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreType.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreType.kt index 59dff6a1..6951cec7 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreType.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreType.kt @@ -125,6 +125,32 @@ class ProjectScoreType @JsonCreator private constructor(private val value: JsonF fun asString(): String = _value().asString().orElseThrow { BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): ProjectScoreType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt index a23ead97..a7496897 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt @@ -9,6 +9,7 @@ import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params +import com.braintrustdata.api.core.allMaxBy import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers @@ -683,10 +684,32 @@ private constructor( config().ifPresent { it.validate() } description() name() - scoreType() + scoreType().ifPresent { it.validate() } validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (categories.asKnown().getOrNull()?.validity() ?: 0) + + (config.asKnown().getOrNull()?.validity() ?: 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (scoreType.asKnown().getOrNull()?.validity() ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -742,14 +765,13 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { categorical != null -> visitor.visitCategorical(categorical) weighted != null -> visitor.visitWeighted(weighted) minimum != null -> visitor.visitMinimum(minimum) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -774,6 +796,35 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitCategorical(categorical: List) = + categorical.sumOf { it.validity().toInt() } + + override fun visitWeighted(weighted: Weighted) = weighted.validity() + + override fun visitMinimum(minimum: List) = minimum.size + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -841,21 +892,30 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): Categories { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef>()) { - it.forEach { it.validate() } - } - ?.let { - return Categories(categorical = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Categories(weighted = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return Categories(minimum = it, _json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Categories(weighted = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef>()) + ?.let { Categories(categorical = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef>())?.let { + Categories(minimum = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with + // all the possible variants (e.g. deserializing from boolean). + 0 -> Categories(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the first + // completely valid match, or simply the first match if none are completely + // valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() } - - return Categories(_json = json) } } @@ -946,6 +1006,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectSettings.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectSettings.kt index 1da46df7..55e71559 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectSettings.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectSettings.kt @@ -248,6 +248,25 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (baselineExperimentId.asKnown().isPresent) 1 else 0) + + (if (comparisonKey.asKnown().isPresent) 1 else 0) + + (spanFieldOrder.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + class SpanFieldOrder private constructor( private val columnId: JsonField, @@ -470,10 +489,31 @@ private constructor( columnId() objectType() position() - layout() + layout().ifPresent { it.validate() } validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (columnId.asKnown().isPresent) 1 else 0) + + (if (objectType.asKnown().isPresent) 1 else 0) + + (if (position.asKnown().isPresent) 1 else 0) + + (layout.asKnown().getOrNull()?.validity() ?: 0) + class Layout @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -563,6 +603,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Layout = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTag.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTag.kt index 4f34c11c..69cc9f76 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTag.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTag.kt @@ -357,6 +357,29 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + (if (color.asKnown().isPresent) 1 else 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagCreateParams.kt index 90fd333b..0ad5056c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagCreateParams.kt @@ -563,6 +563,27 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (color.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt index d388029f..a083440b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.ProjectTagService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -114,6 +115,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt index 9cbb6eca..5612baff 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.ProjectTagServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -116,6 +117,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListParams.kt index bf8907ac..d24144b0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListParams.kt @@ -2,21 +2,10 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.BaseDeserializer -import com.braintrustdata.api.core.BaseSerializer -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.errors.BraintrustInvalidDataException -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -347,13 +336,10 @@ private constructor( * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times */ - @JsonDeserialize(using = Ids.Deserializer::class) - @JsonSerialize(using = Ids.Serializer::class) class Ids private constructor( private val string: String? = null, private val strings: List? = null, - private val _json: JsonValue? = null, ) { fun string(): Optional = Optional.ofNullable(string) @@ -368,15 +354,12 @@ private constructor( fun asStrings(): List = strings.getOrThrow("strings") - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { string != null -> visitor.visitString(string) strings != null -> visitor.visitStrings(strings) - else -> visitor.unknown(_json) + else -> throw IllegalStateException("Invalid Ids") } - } override fun equals(other: Any?): Boolean { if (this === other) { @@ -392,7 +375,6 @@ private constructor( when { string != null -> "Ids{string=$string}" strings != null -> "Ids{strings=$strings}" - _json != null -> "Ids{_unknown=$_json}" else -> throw IllegalStateException("Invalid Ids") } @@ -409,51 +391,6 @@ private constructor( fun visitString(string: String): T fun visitStrings(strings: List): T - - /** - * Maps an unknown variant of [Ids] to a value of type [T]. - * - * An instance of [Ids] can contain an unknown variant if it was deserialized from data - * that doesn't match any known variant. For example, if the SDK is on an older version - * than the API, then the API may respond with new variants that the SDK is unaware of. - * - * @throws BraintrustInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown Ids: $json") - } - } - - internal class Deserializer : BaseDeserializer(Ids::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Ids { - val json = JsonValue.fromJsonNode(node) - - tryDeserialize(node, jacksonTypeRef())?.let { - return Ids(string = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return Ids(strings = it, _json = json) - } - - return Ids(_json = json) - } - } - - internal class Serializer : BaseSerializer(Ids::class) { - - override fun serialize( - value: Ids, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.string != null -> generator.writeObject(value.string) - value.strings != null -> generator.writeObject(value.strings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Ids") - } - } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagReplaceParams.kt index e0f81a0e..dd1ddb62 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagReplaceParams.kt @@ -564,6 +564,27 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (color.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParams.kt index e92812b0..b6c34209 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParams.kt @@ -500,6 +500,26 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (color.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectUpdateParams.kt index 69964f2c..e9434a8a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectUpdateParams.kt @@ -442,6 +442,25 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (settings.asKnown().getOrNull()?.validity() ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Prompt.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Prompt.kt index 1c81b37b..0b817608 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Prompt.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Prompt.kt @@ -599,20 +599,49 @@ private constructor( id() _xactId() - logId() + logId().validate() name() orgId() projectId() slug() created() description() - functionType() + functionType().ifPresent { it.validate() } metadata().ifPresent { it.validate() } promptData().ifPresent { it.validate() } tags() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (_xactId.asKnown().isPresent) 1 else 0) + + (logId.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (orgId.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (slug.asKnown().isPresent) 1 else 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (functionType.asKnown().getOrNull()?.validity() ?: 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (promptData.asKnown().getOrNull()?.validity() ?: 0) + + (tags.asKnown().getOrNull()?.size ?: 0) + /** A literal 'p' which identifies the object as a project prompt */ class LogId @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -695,6 +724,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): LogId = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -810,6 +866,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): FunctionType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -890,6 +973,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptCreateParams.kt index eeb396bc..5e4f31ed 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptCreateParams.kt @@ -789,12 +789,36 @@ private constructor( projectId() slug() description() - functionType() + functionType().ifPresent { it.validate() } promptData().ifPresent { it.validate() } tags() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (slug.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (functionType.asKnown().getOrNull()?.validity() ?: 0) + + (promptData.asKnown().getOrNull()?.validity() ?: 0) + + (tags.asKnown().getOrNull()?.size ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -915,6 +939,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): FunctionType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptData.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptData.kt index 7fc43fbc..5decef33 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptData.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptData.kt @@ -9,6 +9,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.allMaxBy import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow @@ -307,6 +308,27 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (options.asKnown().getOrNull()?.validity() ?: 0) + + (origin.asKnown().getOrNull()?.validity() ?: 0) + + (parser.asKnown().getOrNull()?.validity() ?: 0) + + (prompt.asKnown().getOrNull()?.validity() ?: 0) + + (toolFunctions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + class Origin private constructor( private val projectId: JsonField, @@ -481,6 +503,26 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (promptId.asKnown().isPresent) 1 else 0) + + (if (promptVersion.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -686,11 +728,31 @@ private constructor( } choiceScores().validate() - type() + type().validate() useCot() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (choiceScores.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (if (useCot.asKnown().isPresent) 1 else 0) + class ChoiceScores @JsonCreator private constructor( @@ -760,6 +822,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -858,6 +938,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -912,13 +1019,12 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { completion != null -> visitor.visitCompletion(completion) chat != null -> visitor.visitChat(chat) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -941,6 +1047,32 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitCompletion(completion: Completion) = completion.validity() + + override fun visitChat(chat: Chat) = chat.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -993,16 +1125,28 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): Prompt { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Prompt(completion = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Prompt(chat = it, _json = json) - } - - return Prompt(_json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Prompt(completion = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Prompt(chat = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with + // all the possible variants (e.g. deserializing from boolean). + 0 -> Prompt(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the first + // completely valid match, or simply the first match if none are completely + // valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } } } @@ -1178,10 +1322,29 @@ private constructor( } content() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (content.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -1266,6 +1429,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1520,11 +1710,31 @@ private constructor( } messages().forEach { it.validate() } - type() + type().validate() tools() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (messages.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (if (tools.asKnown().isPresent) 1 else 0) + @JsonDeserialize(using = Message.Deserializer::class) @JsonSerialize(using = Message.Serializer::class) class Message @@ -1576,8 +1786,8 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { system != null -> visitor.visitSystem(system) user != null -> visitor.visitUser(user) assistant != null -> visitor.visitAssistant(assistant) @@ -1586,7 +1796,6 @@ private constructor( fallback != null -> visitor.visitFallback(fallback) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -1625,6 +1834,40 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitSystem(system: System) = system.validity() + + override fun visitUser(user: User) = user.validity() + + override fun visitAssistant(assistant: Assistant) = assistant.validity() + + override fun visitTool(tool: Tool) = tool.validity() + + override fun visitFunction(function: Function) = function.validity() + + override fun visitFallback(fallback: Fallback) = fallback.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1701,32 +1944,41 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): Message { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Message(system = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Message(user = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Message(assistant = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Message(tool = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Message(function = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Message(fallback = it, _json = json) - } - - return Message(_json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Message(system = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Message(user = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Message(assistant = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Message(tool = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Message(function = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Message(fallback = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. deserializing from + // boolean). + 0 -> Message(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use + // the first completely valid match, or simply the first match if none + // are completely valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } } } @@ -1942,12 +2194,32 @@ private constructor( return@apply } - role() + role().validate() content() name() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (role.asKnown().getOrNull()?.validity() ?: 0) + + (if (content.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + class Role @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2036,6 +2308,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Role = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2266,12 +2566,32 @@ private constructor( return@apply } - role() + role().validate() content().ifPresent { it.validate() } name() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (role.asKnown().getOrNull()?.validity() ?: 0) + + (content.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + class Role @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2360,6 +2680,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Role = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2397,13 +2745,12 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { text != null -> visitor.visitText(text) array != null -> visitor.visitArray(array) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -2426,6 +2773,34 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitText(text: String) = 1 + + override fun visitArray( + array: List + ) = array.sumOf { it.validity().toInt() } + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2483,20 +2858,35 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): Content { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef())?.let { - return Content(text = it, _json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Content(text = it, _json = json) + }, + tryDeserialize( + node, + jacksonTypeRef< + List + >(), + ) + ?.let { Content(array = it, _json = json) }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. + // deserializing from object). + 0 -> Content(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, + // then use the first completely valid match, or simply the + // first match if none are completely valid. + else -> + bestMatches.firstOrNull { it.isValid() } + ?: bestMatches.first() } - tryDeserialize( - node, - jacksonTypeRef>(), - ) { - it.forEach { it.validate() } - } - ?.let { - return Content(array = it, _json = json) - } - - return Content(_json = json) } } @@ -2542,13 +2932,12 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { text != null -> visitor.visitText(text) image != null -> visitor.visitImage(image) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -2575,6 +2964,36 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in + * this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitText( + text: ChatCompletionContentPartText + ) = text.validity() + + override fun visitImage( + image: ChatCompletionContentPartImage + ) = image.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2647,32 +3066,49 @@ private constructor( ): ChatCompletionContentPart { val json = JsonValue.fromJsonNode(node) - tryDeserialize( - node, - jacksonTypeRef(), - ) { - it.validate() - } - ?.let { - return ChatCompletionContentPart( - text = it, - _json = json, - ) - } - tryDeserialize( - node, - jacksonTypeRef(), - ) { - it.validate() - } - ?.let { - return ChatCompletionContentPart( - image = it, - _json = json, + val bestMatches = + sequenceOf( + tryDeserialize( + node, + jacksonTypeRef< + ChatCompletionContentPartText + >(), + ) + ?.let { + ChatCompletionContentPart( + text = it, + _json = json, + ) + }, + tryDeserialize( + node, + jacksonTypeRef< + ChatCompletionContentPartImage + >(), + ) + ?.let { + ChatCompletionContentPart( + image = it, + _json = json, + ) + }, ) - } - - return ChatCompletionContentPart(_json = json) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. + // deserializing from boolean). + 0 -> ChatCompletionContentPart(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, + // then use the first completely valid match, or simply the + // first match if none are completely valid. + else -> + bestMatches.firstOrNull { it.isValid() } + ?: bestMatches.first() + } } } @@ -3020,7 +3456,7 @@ private constructor( return@apply } - role() + role().validate() content() functionCall().ifPresent { it.validate() } name() @@ -3028,6 +3464,28 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (role.asKnown().getOrNull()?.validity() ?: 0) + + (if (content.asKnown().isPresent) 1 else 0) + + (functionCall.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (toolCalls.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + class Role @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -3116,6 +3574,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Role = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3301,6 +3787,25 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (arguments.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3534,12 +4039,32 @@ private constructor( return@apply } - role() + role().validate() content() toolCallId() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (role.asKnown().getOrNull()?.validity() ?: 0) + + (if (content.asKnown().isPresent) 1 else 0) + + (if (toolCallId.asKnown().isPresent) 1 else 0) + class Role @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -3628,6 +4153,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Role = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3855,11 +4408,31 @@ private constructor( } name() - role() + role().validate() content() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (role.asKnown().getOrNull()?.validity() ?: 0) + + (if (content.asKnown().isPresent) 1 else 0) + class Role @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -3948,6 +4521,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Role = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -4142,11 +4743,30 @@ private constructor( return@apply } - role() + role().validate() content() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (role.asKnown().getOrNull()?.validity() ?: 0) + + (if (content.asKnown().isPresent) 1 else 0) + class Role @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -4235,6 +4855,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Role = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -4351,6 +4999,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -4406,13 +5081,12 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { function != null -> visitor.visitFunction(function) global != null -> visitor.visitGlobal(global) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -4435,6 +5109,32 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitFunction(function: Function) = function.validity() + + override fun visitGlobal(global: Global) = global.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -4490,16 +5190,28 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): ToolFunction { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return ToolFunction(function = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return ToolFunction(global = it, _json = json) - } - - return ToolFunction(_json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + ToolFunction(function = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + ToolFunction(global = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with + // all the possible variants (e.g. deserializing from boolean). + 0 -> ToolFunction(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the first + // completely valid match, or simply the first match if none are completely + // valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } } } @@ -4673,10 +5385,29 @@ private constructor( } id() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -4761,6 +5492,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -4946,10 +5704,29 @@ private constructor( } name() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -5034,6 +5811,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt index fb903078..812a03e8 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.PromptService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -111,6 +112,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt index bb3ee459..f6405594 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.PromptServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -113,6 +114,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListParams.kt index 09d243ab..a5c5adda 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListParams.kt @@ -2,21 +2,10 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.BaseDeserializer -import com.braintrustdata.api.core.BaseSerializer -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.errors.BraintrustInvalidDataException -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -384,13 +373,10 @@ private constructor( * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times */ - @JsonDeserialize(using = Ids.Deserializer::class) - @JsonSerialize(using = Ids.Serializer::class) class Ids private constructor( private val string: String? = null, private val strings: List? = null, - private val _json: JsonValue? = null, ) { fun string(): Optional = Optional.ofNullable(string) @@ -405,15 +391,12 @@ private constructor( fun asStrings(): List = strings.getOrThrow("strings") - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { string != null -> visitor.visitString(string) strings != null -> visitor.visitStrings(strings) - else -> visitor.unknown(_json) + else -> throw IllegalStateException("Invalid Ids") } - } override fun equals(other: Any?): Boolean { if (this === other) { @@ -429,7 +412,6 @@ private constructor( when { string != null -> "Ids{string=$string}" strings != null -> "Ids{strings=$strings}" - _json != null -> "Ids{_unknown=$_json}" else -> throw IllegalStateException("Invalid Ids") } @@ -446,51 +428,6 @@ private constructor( fun visitString(string: String): T fun visitStrings(strings: List): T - - /** - * Maps an unknown variant of [Ids] to a value of type [T]. - * - * An instance of [Ids] can contain an unknown variant if it was deserialized from data - * that doesn't match any known variant. For example, if the SDK is on an older version - * than the API, then the API may respond with new variants that the SDK is unaware of. - * - * @throws BraintrustInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown Ids: $json") - } - } - - internal class Deserializer : BaseDeserializer(Ids::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Ids { - val json = JsonValue.fromJsonNode(node) - - tryDeserialize(node, jacksonTypeRef())?.let { - return Ids(string = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return Ids(strings = it, _json = json) - } - - return Ids(_json = json) - } - } - - internal class Serializer : BaseSerializer(Ids::class) { - - override fun serialize( - value: Ids, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.string != null -> generator.writeObject(value.string) - value.strings != null -> generator.writeObject(value.strings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Ids") - } - } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptOptions.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptOptions.kt index d060274a..5cd212d0 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptOptions.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptOptions.kt @@ -9,6 +9,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.allMaxBy import com.braintrustdata.api.core.checkKnown import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow @@ -209,6 +210,25 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (model.asKnown().isPresent) 1 else 0) + + (params.asKnown().getOrNull()?.validity() ?: 0) + + (if (position.asKnown().isPresent) 1 else 0) + @JsonDeserialize(using = Params.Deserializer::class) @JsonSerialize(using = Params.Serializer::class) class Params @@ -253,8 +273,8 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { openaiModel != null -> visitor.visitOpenAIModel(openaiModel) anthropicModel != null -> visitor.visitAnthropicModel(anthropicModel) googleModel != null -> visitor.visitGoogleModel(googleModel) @@ -262,7 +282,6 @@ private constructor( jsCompletion != null -> visitor.visitJsCompletion(jsCompletion) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -297,6 +316,43 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitOpenAIModel(openaiModel: OpenAIModelParams) = + openaiModel.validity() + + override fun visitAnthropicModel(anthropicModel: AnthropicModelParams) = + anthropicModel.validity() + + override fun visitGoogleModel(googleModel: GoogleModelParams) = + googleModel.validity() + + override fun visitWindowAiModel(windowAiModel: WindowAiModelParams) = + windowAiModel.validity() + + override fun visitJsCompletion(jsCompletion: JsCompletionParams) = + jsCompletion.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -372,28 +428,37 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): Params { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Params(openaiModel = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Params(anthropicModel = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Params(googleModel = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Params(windowAiModel = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Params(jsCompletion = it, _json = json) - } - - return Params(_json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Params(openaiModel = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Params(anthropicModel = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Params(googleModel = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Params(windowAiModel = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Params(jsCompletion = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with + // all the possible variants (e.g. deserializing from boolean). + 0 -> Params(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the first + // completely valid match, or simply the first match if none are completely + // valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } } } @@ -1039,7 +1104,7 @@ private constructor( maxTokens() n() presencePenalty() - reasoningEffort() + reasoningEffort().ifPresent { it.validate() } responseFormat().ifPresent { it.validate() } stop() temperature() @@ -1049,6 +1114,36 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (frequencyPenalty.asKnown().isPresent) 1 else 0) + + (functionCall.asKnown().getOrNull()?.validity() ?: 0) + + (if (maxCompletionTokens.asKnown().isPresent) 1 else 0) + + (if (maxTokens.asKnown().isPresent) 1 else 0) + + (if (n.asKnown().isPresent) 1 else 0) + + (if (presencePenalty.asKnown().isPresent) 1 else 0) + + (reasoningEffort.asKnown().getOrNull()?.validity() ?: 0) + + (responseFormat.asKnown().getOrNull()?.validity() ?: 0) + + (stop.asKnown().getOrNull()?.size ?: 0) + + (if (temperature.asKnown().isPresent) 1 else 0) + + (toolChoice.asKnown().getOrNull()?.validity() ?: 0) + + (if (topP.asKnown().isPresent) 1 else 0) + + (if (useCache.asKnown().isPresent) 1 else 0) + @JsonDeserialize(using = FunctionCall.Deserializer::class) @JsonSerialize(using = FunctionCall.Serializer::class) class FunctionCall @@ -1072,13 +1167,12 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { unionMember0 != null -> visitor.visitUnionMember0(unionMember0) function != null -> visitor.visitFunction(function) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -1089,7 +1183,9 @@ private constructor( accept( object : Visitor { - override fun visitUnionMember0(unionMember0: UnionMember0) {} + override fun visitUnionMember0(unionMember0: UnionMember0) { + unionMember0.validate() + } override fun visitFunction(function: Function) { function.validate() @@ -1099,6 +1195,33 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitUnionMember0(unionMember0: UnionMember0) = + unionMember0.validity() + + override fun visitFunction(function: Function) = function.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1157,15 +1280,29 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): FunctionCall { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef())?.let { - return FunctionCall(unionMember0 = it, _json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + FunctionCall(unionMember0 = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + FunctionCall(function = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. deserializing from + // array). + 0 -> FunctionCall(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use + // the first completely valid match, or simply the first match if none + // are completely valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return FunctionCall(function = it, _json = json) - } - - return FunctionCall(_json = json) } } @@ -1281,6 +1418,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): UnionMember0 = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1423,6 +1588,23 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = (if (name.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1543,6 +1725,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): ReasoningEffort = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1586,14 +1795,13 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { jsonObject != null -> visitor.visitJsonObject(jsonObject) jsonSchema != null -> visitor.visitJsonSchema(jsonSchema) text != null -> visitor.visitText(text) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -1620,6 +1828,36 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitJsonObject(jsonObject: JsonObject) = + jsonObject.validity() + + override fun visitJsonSchema(jsonSchema: JsonSchema) = + jsonSchema.validity() + + override fun visitText(text: Text) = text.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1685,20 +1923,32 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): ResponseFormat { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return ResponseFormat(jsonObject = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return ResponseFormat(jsonSchema = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return ResponseFormat(text = it, _json = json) - } - - return ResponseFormat(_json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + ResponseFormat(jsonObject = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + ResponseFormat(jsonSchema = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + ResponseFormat(text = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. deserializing from + // boolean). + 0 -> ResponseFormat(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use + // the first completely valid match, or simply the first match if none + // are completely valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } } } @@ -1844,10 +2094,27 @@ private constructor( return@apply } - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = (type.asKnown().getOrNull()?.validity() ?: 0) + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -1936,6 +2203,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2133,10 +2428,29 @@ private constructor( } jsonSchema().validate() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (jsonSchema.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + class InnerJsonSchema private constructor( private val name: JsonField, @@ -2399,6 +2713,27 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (schema.asKnown().getOrNull()?.validity() ?: 0) + + (if (strict.asKnown().isPresent) 1 else 0) + @JsonDeserialize(using = Schema.Deserializer::class) @JsonSerialize(using = Schema.Serializer::class) class Schema @@ -2422,13 +2757,12 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { object_ != null -> visitor.visitObject(object_) string != null -> visitor.visitString(string) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -2449,6 +2783,33 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in + * this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitObject(object_: Object) = + object_.validity() + + override fun visitString(string: String) = 1 + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2505,15 +2866,29 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): Schema { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return Schema(object_ = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef())?.let { - return Schema(string = it, _json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef()) + ?.let { Schema(object_ = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { Schema(string = it, _json = json) }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. + // deserializing from array). + 0 -> Schema(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, + // then use the first completely valid match, or simply the + // first match if none are completely valid. + else -> + bestMatches.firstOrNull { it.isValid() } + ?: bestMatches.first() } - - return Schema(_json = json) } } @@ -2615,6 +2990,26 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in + * this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2740,6 +3135,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2893,10 +3316,27 @@ private constructor( return@apply } - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = (type.asKnown().getOrNull()?.validity() ?: 0) + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2985,6 +3425,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3040,13 +3508,12 @@ private constructor( fun _json(): Optional = Optional.ofNullable(_json) - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { unionMember0 != null -> visitor.visitUnionMember0(unionMember0) function != null -> visitor.visitFunction(function) else -> visitor.unknown(_json) } - } private var validated: Boolean = false @@ -3057,7 +3524,9 @@ private constructor( accept( object : Visitor { - override fun visitUnionMember0(unionMember0: UnionMember0) {} + override fun visitUnionMember0(unionMember0: UnionMember0) { + unionMember0.validate() + } override fun visitFunction(function: Function) { function.validate() @@ -3067,6 +3536,33 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitUnionMember0(unionMember0: UnionMember0) = + unionMember0.validity() + + override fun visitFunction(function: Function) = function.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3124,15 +3620,29 @@ private constructor( override fun ObjectCodec.deserialize(node: JsonNode): ToolChoice { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef())?.let { - return ToolChoice(unionMember0 = it, _json = json) + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + ToolChoice(unionMember0 = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + ToolChoice(function = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. deserializing from + // array). + 0 -> ToolChoice(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use + // the first completely valid match, or simply the first match if none + // are completely valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return ToolChoice(function = it, _json = json) - } - - return ToolChoice(_json = json) } } @@ -3254,6 +3764,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): UnionMember0 = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3432,10 +3970,29 @@ private constructor( } function().validate() - type() + type().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (function.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + class InnerFunction private constructor( private val name: JsonField, @@ -3568,6 +4125,23 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = (if (name.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3674,6 +4248,34 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -4092,6 +4694,30 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (maxTokens.asKnown().isPresent) 1 else 0) + + (if (temperature.asKnown().isPresent) 1 else 0) + + (if (maxTokensToSample.asKnown().isPresent) 1 else 0) + + (stopSequences.asKnown().getOrNull()?.size ?: 0) + + (if (topK.asKnown().isPresent) 1 else 0) + + (if (topP.asKnown().isPresent) 1 else 0) + + (if (useCache.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -4365,6 +4991,28 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (maxOutputTokens.asKnown().isPresent) 1 else 0) + + (if (temperature.asKnown().isPresent) 1 else 0) + + (if (topK.asKnown().isPresent) 1 else 0) + + (if (topP.asKnown().isPresent) 1 else 0) + + (if (useCache.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -4569,6 +5217,26 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (temperature.asKnown().isPresent) 1 else 0) + + (if (topK.asKnown().isPresent) 1 else 0) + + (if (useCache.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -4702,6 +5370,23 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = (if (useCache.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptReplaceParams.kt index 5039be57..1368dcaf 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptReplaceParams.kt @@ -789,12 +789,36 @@ private constructor( projectId() slug() description() - functionType() + functionType().ifPresent { it.validate() } promptData().ifPresent { it.validate() } tags() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (slug.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (functionType.asKnown().getOrNull()?.validity() ?: 0) + + (promptData.asKnown().getOrNull()?.validity() ?: 0) + + (tags.asKnown().getOrNull()?.size ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -915,6 +939,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): FunctionType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt index bfd3b27e..ba01dab9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt @@ -666,6 +666,28 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (description.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (promptData.asKnown().getOrNull()?.validity() ?: 0) + + (if (slug.asKnown().isPresent) 1 else 0) + + (tags.asKnown().getOrNull()?.size ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RepoInfo.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RepoInfo.kt index a6081b97..d4dd9d9c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RepoInfo.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RepoInfo.kt @@ -453,6 +453,31 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (authorEmail.asKnown().isPresent) 1 else 0) + + (if (authorName.asKnown().isPresent) 1 else 0) + + (if (branch.asKnown().isPresent) 1 else 0) + + (if (commit.asKnown().isPresent) 1 else 0) + + (if (commitMessage.asKnown().isPresent) 1 else 0) + + (if (commitTime.asKnown().isPresent) 1 else 0) + + (if (dirty.asKnown().isPresent) 1 else 0) + + (if (gitDiff.asKnown().isPresent) 1 else 0) + + (if (tag.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Role.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Role.kt index c9c1c582..a977c315 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Role.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Role.kt @@ -514,6 +514,31 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (if (deletedAt.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (memberPermissions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (memberRoles.asKnown().getOrNull()?.size ?: 0) + + (if (orgId.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + class MemberPermission private constructor( private val permission: JsonField, @@ -695,11 +720,30 @@ private constructor( return@apply } - permission() - restrictObjectType() + permission().validate() + restrictObjectType().ifPresent { it.validate() } validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (permission.asKnown().getOrNull()?.validity() ?: 0) + + (restrictObjectType.asKnown().getOrNull()?.validity() ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleCreateParams.kt index c90a6954..92863dc8 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleCreateParams.kt @@ -724,6 +724,28 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (memberPermissions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (memberRoles.asKnown().getOrNull()?.size ?: 0) + + (if (orgName.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -923,11 +945,30 @@ private constructor( return@apply } - permission() - restrictObjectType() + permission().validate() + restrictObjectType().ifPresent { it.validate() } validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (permission.asKnown().getOrNull()?.validity() ?: 0) + + (restrictObjectType.asKnown().getOrNull()?.validity() ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt index aeb09d72..37e67991 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.RoleService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -111,6 +112,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt index b75ec089..6c637a90 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.RoleServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -113,6 +114,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListParams.kt index a75c101a..f90f054c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListParams.kt @@ -2,21 +2,10 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.BaseDeserializer -import com.braintrustdata.api.core.BaseSerializer -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.errors.BraintrustInvalidDataException -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -318,13 +307,10 @@ private constructor( * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times */ - @JsonDeserialize(using = Ids.Deserializer::class) - @JsonSerialize(using = Ids.Serializer::class) class Ids private constructor( private val string: String? = null, private val strings: List? = null, - private val _json: JsonValue? = null, ) { fun string(): Optional = Optional.ofNullable(string) @@ -339,15 +325,12 @@ private constructor( fun asStrings(): List = strings.getOrThrow("strings") - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { string != null -> visitor.visitString(string) strings != null -> visitor.visitStrings(strings) - else -> visitor.unknown(_json) + else -> throw IllegalStateException("Invalid Ids") } - } override fun equals(other: Any?): Boolean { if (this === other) { @@ -363,7 +346,6 @@ private constructor( when { string != null -> "Ids{string=$string}" strings != null -> "Ids{strings=$strings}" - _json != null -> "Ids{_unknown=$_json}" else -> throw IllegalStateException("Invalid Ids") } @@ -380,51 +362,6 @@ private constructor( fun visitString(string: String): T fun visitStrings(strings: List): T - - /** - * Maps an unknown variant of [Ids] to a value of type [T]. - * - * An instance of [Ids] can contain an unknown variant if it was deserialized from data - * that doesn't match any known variant. For example, if the SDK is on an older version - * than the API, then the API may respond with new variants that the SDK is unaware of. - * - * @throws BraintrustInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown Ids: $json") - } - } - - internal class Deserializer : BaseDeserializer(Ids::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Ids { - val json = JsonValue.fromJsonNode(node) - - tryDeserialize(node, jacksonTypeRef())?.let { - return Ids(string = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return Ids(strings = it, _json = json) - } - - return Ids(_json = json) - } - } - - internal class Serializer : BaseSerializer(Ids::class) { - - override fun serialize( - value: Ids, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.string != null -> generator.writeObject(value.string) - value.strings != null -> generator.writeObject(value.strings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Ids") - } - } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleReplaceParams.kt index 73ece3a4..30262b1e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleReplaceParams.kt @@ -728,6 +728,28 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (memberPermissions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (memberRoles.asKnown().getOrNull()?.size ?: 0) + + (if (orgName.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -927,11 +949,30 @@ private constructor( return@apply } - permission() - restrictObjectType() + permission().validate() + restrictObjectType().ifPresent { it.validate() } validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (permission.asKnown().getOrNull()?.validity() ?: 0) + + (restrictObjectType.asKnown().getOrNull()?.validity() ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleUpdateParams.kt index c45164b0..16f9816b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleUpdateParams.kt @@ -885,6 +885,30 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (addMemberPermissions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (addMemberRoles.asKnown().getOrNull()?.size ?: 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (removeMemberPermissions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (removeMemberRoles.asKnown().getOrNull()?.size ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1084,11 +1108,30 @@ private constructor( return@apply } - permission() - restrictObjectType() + permission().validate() + restrictObjectType().ifPresent { it.validate() } validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (permission.asKnown().getOrNull()?.validity() ?: 0) + + (restrictObjectType.asKnown().getOrNull()?.validity() ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1288,11 +1331,30 @@ private constructor( return@apply } - permission() - restrictObjectType() + permission().validate() + restrictObjectType().ifPresent { it.validate() } validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (permission.asKnown().getOrNull()?.validity() ?: 0) + + (restrictObjectType.asKnown().getOrNull()?.validity() ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ScoreSummary.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ScoreSummary.kt index b74de965..bd494f33 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ScoreSummary.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ScoreSummary.kt @@ -282,6 +282,27 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (improvements.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (regressions.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + (if (diff.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanAttributes.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanAttributes.kt index b0d8307a..21bd09b0 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanAttributes.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanAttributes.kt @@ -156,10 +156,27 @@ private constructor( } name() - type() + type().ifPresent { it.validate() } validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + (type.asKnown().getOrNull()?.validity() ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIFrame.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIFrame.kt index cb222f2c..4d67a41a 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIFrame.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIFrame.kt @@ -460,6 +460,31 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (url.asKnown().isPresent) 1 else 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (if (deletedAt.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (if (postMessage.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeCreateParams.kt index ba9059c9..b4640f20 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeCreateParams.kt @@ -656,6 +656,28 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (url.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (if (postMessage.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt index 56719e29..ac913dfe 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.SpanIframeService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -114,6 +115,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt index 3ff61ee7..3f6112ce 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.SpanIframeServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -116,6 +117,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListParams.kt index 36d6b9de..7ad05511 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListParams.kt @@ -2,21 +2,10 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.BaseDeserializer -import com.braintrustdata.api.core.BaseSerializer -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.errors.BraintrustInvalidDataException -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -319,13 +308,10 @@ private constructor( * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times */ - @JsonDeserialize(using = Ids.Deserializer::class) - @JsonSerialize(using = Ids.Serializer::class) class Ids private constructor( private val string: String? = null, private val strings: List? = null, - private val _json: JsonValue? = null, ) { fun string(): Optional = Optional.ofNullable(string) @@ -340,15 +326,12 @@ private constructor( fun asStrings(): List = strings.getOrThrow("strings") - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { string != null -> visitor.visitString(string) strings != null -> visitor.visitStrings(strings) - else -> visitor.unknown(_json) + else -> throw IllegalStateException("Invalid Ids") } - } override fun equals(other: Any?): Boolean { if (this === other) { @@ -364,7 +347,6 @@ private constructor( when { string != null -> "Ids{string=$string}" strings != null -> "Ids{strings=$strings}" - _json != null -> "Ids{_unknown=$_json}" else -> throw IllegalStateException("Invalid Ids") } @@ -381,51 +363,6 @@ private constructor( fun visitString(string: String): T fun visitStrings(strings: List): T - - /** - * Maps an unknown variant of [Ids] to a value of type [T]. - * - * An instance of [Ids] can contain an unknown variant if it was deserialized from data - * that doesn't match any known variant. For example, if the SDK is on an older version - * than the API, then the API may respond with new variants that the SDK is unaware of. - * - * @throws BraintrustInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown Ids: $json") - } - } - - internal class Deserializer : BaseDeserializer(Ids::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Ids { - val json = JsonValue.fromJsonNode(node) - - tryDeserialize(node, jacksonTypeRef())?.let { - return Ids(string = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return Ids(strings = it, _json = json) - } - - return Ids(_json = json) - } - } - - internal class Serializer : BaseSerializer(Ids::class) { - - override fun serialize( - value: Ids, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.string != null -> generator.writeObject(value.string) - value.strings != null -> generator.writeObject(value.strings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Ids") - } - } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeReplaceParams.kt index f6375deb..fdc7b73d 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeReplaceParams.kt @@ -656,6 +656,28 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (url.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (if (postMessage.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParams.kt index 865a00b7..30e68c47 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParams.kt @@ -595,6 +595,27 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (description.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (postMessage.asKnown().isPresent) 1 else 0) + + (if (url.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanType.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanType.kt index 2c558123..33527e47 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanType.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanType.kt @@ -116,6 +116,32 @@ class SpanType @JsonCreator private constructor(private val value: JsonField !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -545,6 +586,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/User.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/User.kt index d0bbfc7b..317fbc17 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/User.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/User.kt @@ -324,6 +324,28 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (avatarUrl.asKnown().isPresent) 1 else 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (if (email.asKnown().isPresent) 1 else 0) + + (if (familyName.asKnown().isPresent) 1 else 0) + + (if (givenName.asKnown().isPresent) 1 else 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt index e2a4b2d7..ce3e3325 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.UserService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -111,6 +112,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt index 4942040a..fa4e3654 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.UserServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -113,6 +114,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListParams.kt index 46e6805d..70081294 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListParams.kt @@ -2,21 +2,10 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.BaseDeserializer -import com.braintrustdata.api.core.BaseSerializer -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.errors.BraintrustInvalidDataException -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -412,13 +401,10 @@ private constructor( * Email of the user to search for. You may pass the param multiple times to filter for more * than one email */ - @JsonDeserialize(using = Email.Deserializer::class) - @JsonSerialize(using = Email.Serializer::class) class Email private constructor( private val string: String? = null, private val strings: List? = null, - private val _json: JsonValue? = null, ) { fun string(): Optional = Optional.ofNullable(string) @@ -433,15 +419,12 @@ private constructor( fun asStrings(): List = strings.getOrThrow("strings") - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { string != null -> visitor.visitString(string) strings != null -> visitor.visitStrings(strings) - else -> visitor.unknown(_json) + else -> throw IllegalStateException("Invalid Email") } - } override fun equals(other: Any?): Boolean { if (this === other) { @@ -457,7 +440,6 @@ private constructor( when { string != null -> "Email{string=$string}" strings != null -> "Email{strings=$strings}" - _json != null -> "Email{_unknown=$_json}" else -> throw IllegalStateException("Invalid Email") } @@ -474,52 +456,6 @@ private constructor( fun visitString(string: String): T fun visitStrings(strings: List): T - - /** - * Maps an unknown variant of [Email] to a value of type [T]. - * - * An instance of [Email] can contain an unknown variant if it was deserialized from - * data that doesn't match any known variant. For example, if the SDK is on an older - * version than the API, then the API may respond with new variants that the SDK is - * unaware of. - * - * @throws BraintrustInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown Email: $json") - } - } - - internal class Deserializer : BaseDeserializer(Email::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Email { - val json = JsonValue.fromJsonNode(node) - - tryDeserialize(node, jacksonTypeRef())?.let { - return Email(string = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return Email(strings = it, _json = json) - } - - return Email(_json = json) - } - } - - internal class Serializer : BaseSerializer(Email::class) { - - override fun serialize( - value: Email, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.string != null -> generator.writeObject(value.string) - value.strings != null -> generator.writeObject(value.strings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Email") - } - } } } @@ -527,13 +463,10 @@ private constructor( * Family name of the user to search for. You may pass the param multiple times to filter for * more than one family name */ - @JsonDeserialize(using = FamilyName.Deserializer::class) - @JsonSerialize(using = FamilyName.Serializer::class) class FamilyName private constructor( private val string: String? = null, private val strings: List? = null, - private val _json: JsonValue? = null, ) { fun string(): Optional = Optional.ofNullable(string) @@ -548,15 +481,12 @@ private constructor( fun asStrings(): List = strings.getOrThrow("strings") - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { string != null -> visitor.visitString(string) strings != null -> visitor.visitStrings(strings) - else -> visitor.unknown(_json) + else -> throw IllegalStateException("Invalid FamilyName") } - } override fun equals(other: Any?): Boolean { if (this === other) { @@ -572,7 +502,6 @@ private constructor( when { string != null -> "FamilyName{string=$string}" strings != null -> "FamilyName{strings=$strings}" - _json != null -> "FamilyName{_unknown=$_json}" else -> throw IllegalStateException("Invalid FamilyName") } @@ -591,52 +520,6 @@ private constructor( fun visitString(string: String): T fun visitStrings(strings: List): T - - /** - * Maps an unknown variant of [FamilyName] to a value of type [T]. - * - * An instance of [FamilyName] can contain an unknown variant if it was deserialized - * from data that doesn't match any known variant. For example, if the SDK is on an - * older version than the API, then the API may respond with new variants that the SDK - * is unaware of. - * - * @throws BraintrustInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown FamilyName: $json") - } - } - - internal class Deserializer : BaseDeserializer(FamilyName::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): FamilyName { - val json = JsonValue.fromJsonNode(node) - - tryDeserialize(node, jacksonTypeRef())?.let { - return FamilyName(string = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return FamilyName(strings = it, _json = json) - } - - return FamilyName(_json = json) - } - } - - internal class Serializer : BaseSerializer(FamilyName::class) { - - override fun serialize( - value: FamilyName, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.string != null -> generator.writeObject(value.string) - value.strings != null -> generator.writeObject(value.strings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid FamilyName") - } - } } } @@ -644,13 +527,10 @@ private constructor( * Given name of the user to search for. You may pass the param multiple times to filter for * more than one given name */ - @JsonDeserialize(using = GivenName.Deserializer::class) - @JsonSerialize(using = GivenName.Serializer::class) class GivenName private constructor( private val string: String? = null, private val strings: List? = null, - private val _json: JsonValue? = null, ) { fun string(): Optional = Optional.ofNullable(string) @@ -665,15 +545,12 @@ private constructor( fun asStrings(): List = strings.getOrThrow("strings") - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { string != null -> visitor.visitString(string) strings != null -> visitor.visitStrings(strings) - else -> visitor.unknown(_json) + else -> throw IllegalStateException("Invalid GivenName") } - } override fun equals(other: Any?): Boolean { if (this === other) { @@ -689,7 +566,6 @@ private constructor( when { string != null -> "GivenName{string=$string}" strings != null -> "GivenName{strings=$strings}" - _json != null -> "GivenName{_unknown=$_json}" else -> throw IllegalStateException("Invalid GivenName") } @@ -708,52 +584,6 @@ private constructor( fun visitString(string: String): T fun visitStrings(strings: List): T - - /** - * Maps an unknown variant of [GivenName] to a value of type [T]. - * - * An instance of [GivenName] can contain an unknown variant if it was deserialized from - * data that doesn't match any known variant. For example, if the SDK is on an older - * version than the API, then the API may respond with new variants that the SDK is - * unaware of. - * - * @throws BraintrustInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown GivenName: $json") - } - } - - internal class Deserializer : BaseDeserializer(GivenName::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): GivenName { - val json = JsonValue.fromJsonNode(node) - - tryDeserialize(node, jacksonTypeRef())?.let { - return GivenName(string = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return GivenName(strings = it, _json = json) - } - - return GivenName(_json = json) - } - } - - internal class Serializer : BaseSerializer(GivenName::class) { - - override fun serialize( - value: GivenName, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.string != null -> generator.writeObject(value.string) - value.strings != null -> generator.writeObject(value.strings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid GivenName") - } - } } } @@ -761,13 +591,10 @@ private constructor( * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times */ - @JsonDeserialize(using = Ids.Deserializer::class) - @JsonSerialize(using = Ids.Serializer::class) class Ids private constructor( private val string: String? = null, private val strings: List? = null, - private val _json: JsonValue? = null, ) { fun string(): Optional = Optional.ofNullable(string) @@ -782,15 +609,12 @@ private constructor( fun asStrings(): List = strings.getOrThrow("strings") - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { string != null -> visitor.visitString(string) strings != null -> visitor.visitStrings(strings) - else -> visitor.unknown(_json) + else -> throw IllegalStateException("Invalid Ids") } - } override fun equals(other: Any?): Boolean { if (this === other) { @@ -806,7 +630,6 @@ private constructor( when { string != null -> "Ids{string=$string}" strings != null -> "Ids{strings=$strings}" - _json != null -> "Ids{_unknown=$_json}" else -> throw IllegalStateException("Invalid Ids") } @@ -823,51 +646,6 @@ private constructor( fun visitString(string: String): T fun visitStrings(strings: List): T - - /** - * Maps an unknown variant of [Ids] to a value of type [T]. - * - * An instance of [Ids] can contain an unknown variant if it was deserialized from data - * that doesn't match any known variant. For example, if the SDK is on an older version - * than the API, then the API may respond with new variants that the SDK is unaware of. - * - * @throws BraintrustInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown Ids: $json") - } - } - - internal class Deserializer : BaseDeserializer(Ids::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Ids { - val json = JsonValue.fromJsonNode(node) - - tryDeserialize(node, jacksonTypeRef())?.let { - return Ids(string = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return Ids(strings = it, _json = json) - } - - return Ids(_json = json) - } - } - - internal class Serializer : BaseSerializer(Ids::class) { - - override fun serialize( - value: Ids, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.string != null -> generator.writeObject(value.string) - value.strings != null -> generator.writeObject(value.strings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Ids") - } - } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/View.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/View.kt index d6f9dc50..82c22250 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/View.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/View.kt @@ -477,8 +477,8 @@ private constructor( id() name() objectId() - objectType() - viewType() + objectType().validate() + viewType().ifPresent { it.validate() } created() deletedAt() options().ifPresent { it.validate() } @@ -487,6 +487,32 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (objectId.asKnown().isPresent) 1 else 0) + + (objectType.asKnown().getOrNull()?.validity() ?: 0) + + (viewType.asKnown().getOrNull()?.validity() ?: 0) + + (if (created.asKnown().isPresent) 1 else 0) + + (if (deletedAt.asKnown().isPresent) 1 else 0) + + (options.asKnown().getOrNull()?.validity() ?: 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + (viewData.asKnown().getOrNull()?.validity() ?: 0) + /** Type of table that the view corresponds to. */ class ViewType @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -629,6 +655,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): ViewType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewCreateParams.kt index 53dae27a..581e3acd 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewCreateParams.kt @@ -839,8 +839,8 @@ private constructor( name() objectId() - objectType() - viewType() + objectType().validate() + viewType().ifPresent { it.validate() } deletedAt() options().ifPresent { it.validate() } userId() @@ -848,6 +848,31 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (if (objectId.asKnown().isPresent) 1 else 0) + + (objectType.asKnown().getOrNull()?.validity() ?: 0) + + (viewType.asKnown().getOrNull()?.validity() ?: 0) + + (if (deletedAt.asKnown().isPresent) 1 else 0) + + (options.asKnown().getOrNull()?.validity() ?: 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + (viewData.asKnown().getOrNull()?.validity() ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1008,6 +1033,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): ViewType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewData.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewData.kt index 9854e113..f9e772d0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewData.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewData.kt @@ -123,6 +123,21 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (search.asKnown().getOrNull()?.validity() ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDataSearch.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDataSearch.kt index e621ac3b..5907303b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDataSearch.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDataSearch.kt @@ -285,6 +285,26 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (filter.asKnown().getOrNull()?.sumOf { (if (it == null) 0 else 1).toInt() } ?: 0) + + (match.asKnown().getOrNull()?.sumOf { (if (it == null) 0 else 1).toInt() } ?: 0) + + (sort.asKnown().getOrNull()?.sumOf { (if (it == null) 0 else 1).toInt() } ?: 0) + + (tag.asKnown().getOrNull()?.sumOf { (if (it == null) 0 else 1).toInt() } ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDeleteParams.kt index 6c0fbabe..d5554c7a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDeleteParams.kt @@ -17,6 +17,7 @@ import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.util.Collections import java.util.Objects +import kotlin.jvm.optionals.getOrNull /** Delete a view object by its id */ class ViewDeleteParams @@ -440,10 +441,29 @@ private constructor( } objectId() - objectType() + objectType().validate() validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (objectId.asKnown().isPresent) 1 else 0) + + (objectType.asKnown().getOrNull()?.validity() ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt index 782eae28..d460ef58 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.ViewService import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -111,6 +112,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt index 88c4c372..cdaed4f6 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.ExcludeMissing import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.ViewServiceAsync import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -113,6 +114,14 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + fun toBuilder() = Builder().from(this) override fun equals(other: Any?): Boolean { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListParams.kt index 67a9b81b..decac7ce 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListParams.kt @@ -2,22 +2,11 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.BaseDeserializer -import com.braintrustdata.api.core.BaseSerializer -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams -import com.braintrustdata.api.errors.BraintrustInvalidDataException -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -355,13 +344,10 @@ private constructor( * Filter search results to a particular set of object IDs. To specify a list of IDs, include * the query param multiple times */ - @JsonDeserialize(using = Ids.Deserializer::class) - @JsonSerialize(using = Ids.Serializer::class) class Ids private constructor( private val string: String? = null, private val strings: List? = null, - private val _json: JsonValue? = null, ) { fun string(): Optional = Optional.ofNullable(string) @@ -376,15 +362,12 @@ private constructor( fun asStrings(): List = strings.getOrThrow("strings") - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T { - return when { + fun accept(visitor: Visitor): T = + when { string != null -> visitor.visitString(string) strings != null -> visitor.visitStrings(strings) - else -> visitor.unknown(_json) + else -> throw IllegalStateException("Invalid Ids") } - } override fun equals(other: Any?): Boolean { if (this === other) { @@ -400,7 +383,6 @@ private constructor( when { string != null -> "Ids{string=$string}" strings != null -> "Ids{strings=$strings}" - _json != null -> "Ids{_unknown=$_json}" else -> throw IllegalStateException("Invalid Ids") } @@ -417,51 +399,6 @@ private constructor( fun visitString(string: String): T fun visitStrings(strings: List): T - - /** - * Maps an unknown variant of [Ids] to a value of type [T]. - * - * An instance of [Ids] can contain an unknown variant if it was deserialized from data - * that doesn't match any known variant. For example, if the SDK is on an older version - * than the API, then the API may respond with new variants that the SDK is unaware of. - * - * @throws BraintrustInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw BraintrustInvalidDataException("Unknown Ids: $json") - } - } - - internal class Deserializer : BaseDeserializer(Ids::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Ids { - val json = JsonValue.fromJsonNode(node) - - tryDeserialize(node, jacksonTypeRef())?.let { - return Ids(string = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef>())?.let { - return Ids(strings = it, _json = json) - } - - return Ids(_json = json) - } - } - - internal class Serializer : BaseSerializer(Ids::class) { - - override fun serialize( - value: Ids, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.string != null -> generator.writeObject(value.string) - value.strings != null -> generator.writeObject(value.strings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Ids") - } - } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewOptions.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewOptions.kt index 000a9ce4..4b2f9aeb 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewOptions.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewOptions.kt @@ -338,6 +338,28 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (columnOrder.asKnown().getOrNull()?.size ?: 0) + + (columnSizing.asKnown().getOrNull()?.validity() ?: 0) + + (columnVisibility.asKnown().getOrNull()?.validity() ?: 0) + + (if (grouping.asKnown().isPresent) 1 else 0) + + (if (layout.asKnown().isPresent) 1 else 0) + + (if (rowHeight.asKnown().isPresent) 1 else 0) + class ColumnSizing @JsonCreator private constructor( @@ -404,6 +426,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -487,6 +527,24 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewReplaceParams.kt index 95d8a7ae..8bb91df4 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewReplaceParams.kt @@ -843,8 +843,8 @@ private constructor( name() objectId() - objectType() - viewType() + objectType().validate() + viewType().ifPresent { it.validate() } deletedAt() options().ifPresent { it.validate() } userId() @@ -852,6 +852,31 @@ private constructor( validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (if (objectId.asKnown().isPresent) 1 else 0) + + (objectType.asKnown().getOrNull()?.validity() ?: 0) + + (viewType.asKnown().getOrNull()?.validity() ?: 0) + + (if (deletedAt.asKnown().isPresent) 1 else 0) + + (options.asKnown().getOrNull()?.validity() ?: 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + (viewData.asKnown().getOrNull()?.validity() ?: 0) + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1012,6 +1037,33 @@ private constructor( BraintrustInvalidDataException("Value is not a String") } + private var validated: Boolean = false + + fun validate(): ViewType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewType.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewType.kt index f09a7f19..9f8db16f 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewType.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewType.kt @@ -146,6 +146,32 @@ class ViewType @JsonCreator private constructor(private val value: JsonField(), + ) + + assertThat(roundtrippedAiSecret).isEqualTo(aiSecret) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclBatchUpdateResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclBatchUpdateResponseTest.kt index 4b3ec7dd..e414f12a 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclBatchUpdateResponseTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclBatchUpdateResponseTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -73,4 +75,48 @@ internal class AclBatchUpdateResponseTest { .build() ) } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val aclBatchUpdateResponse = + AclBatchUpdateResponse.builder() + .addAddedAcl( + Acl.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + ._objectOrgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(AclObjectType.ORGANIZATION) + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .groupId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .permission(Permission.CREATE) + .restrictObjectType(AclObjectType.ORGANIZATION) + .roleId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .addRemovedAcl( + Acl.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + ._objectOrgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(AclObjectType.ORGANIZATION) + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .groupId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .permission(Permission.CREATE) + .restrictObjectType(AclObjectType.ORGANIZATION) + .roleId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .build() + + val roundtrippedAclBatchUpdateResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(aclBatchUpdateResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedAclBatchUpdateResponse).isEqualTo(aclBatchUpdateResponse) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclTest.kt index a29f2f9d..862ff24d 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -35,4 +37,27 @@ internal class AclTest { assertThat(acl.roleId()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(acl.userId()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val acl = + Acl.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + ._objectOrgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(AclObjectType.ORGANIZATION) + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .groupId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .permission(Permission.CREATE) + .restrictObjectType(AclObjectType.ORGANIZATION) + .roleId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + val roundtrippedAcl = + jsonMapper.readValue(jsonMapper.writeValueAsString(acl), jacksonTypeRef()) + + assertThat(roundtrippedAcl).isEqualTo(acl) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ApiKeyTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ApiKeyTest.kt index bc43594f..0bda4c73 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ApiKeyTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ApiKeyTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -27,4 +29,23 @@ internal class ApiKeyTest { assertThat(apiKey.orgId()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(apiKey.userId()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val apiKey = + ApiKey.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .previewName("preview_name") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + val roundtrippedApiKey = + jsonMapper.readValue(jsonMapper.writeValueAsString(apiKey), jacksonTypeRef()) + + assertThat(roundtrippedApiKey).isEqualTo(apiKey) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImageTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImageTest.kt index 57b5da08..ccce4723 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImageTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImageTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -30,4 +32,28 @@ internal class ChatCompletionContentPartImageTest { assertThat(chatCompletionContentPartImage.type()) .isEqualTo(ChatCompletionContentPartImage.Type.IMAGE_URL) } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val chatCompletionContentPartImage = + ChatCompletionContentPartImage.builder() + .imageUrl( + ChatCompletionContentPartImage.ImageUrl.builder() + .url("url") + .detail(ChatCompletionContentPartImage.ImageUrl.Detail.AUTO) + .build() + ) + .type(ChatCompletionContentPartImage.Type.IMAGE_URL) + .build() + + val roundtrippedChatCompletionContentPartImage = + jsonMapper.readValue( + jsonMapper.writeValueAsString(chatCompletionContentPartImage), + jacksonTypeRef(), + ) + + assertThat(roundtrippedChatCompletionContentPartImage) + .isEqualTo(chatCompletionContentPartImage) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartTextTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartTextTest.kt index 5c43426a..23dea46b 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartTextTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartTextTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -19,4 +21,23 @@ internal class ChatCompletionContentPartTextTest { .isEqualTo(ChatCompletionContentPartText.Type.TEXT) assertThat(chatCompletionContentPartText.text()).contains("text") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val chatCompletionContentPartText = + ChatCompletionContentPartText.builder() + .type(ChatCompletionContentPartText.Type.TEXT) + .text("text") + .build() + + val roundtrippedChatCompletionContentPartText = + jsonMapper.readValue( + jsonMapper.writeValueAsString(chatCompletionContentPartText), + jacksonTypeRef(), + ) + + assertThat(roundtrippedChatCompletionContentPartText) + .isEqualTo(chatCompletionContentPartText) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ChatCompletionMessageToolCallTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ChatCompletionMessageToolCallTest.kt index 9c78253b..4ff757fd 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ChatCompletionMessageToolCallTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ChatCompletionMessageToolCallTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -32,4 +34,29 @@ internal class ChatCompletionMessageToolCallTest { assertThat(chatCompletionMessageToolCall.type()) .isEqualTo(ChatCompletionMessageToolCall.Type.FUNCTION) } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val chatCompletionMessageToolCall = + ChatCompletionMessageToolCall.builder() + .id("id") + .function( + ChatCompletionMessageToolCall.Function.builder() + .arguments("arguments") + .name("name") + .build() + ) + .type(ChatCompletionMessageToolCall.Type.FUNCTION) + .build() + + val roundtrippedChatCompletionMessageToolCall = + jsonMapper.readValue( + jsonMapper.writeValueAsString(chatCompletionMessageToolCall), + jacksonTypeRef(), + ) + + assertThat(roundtrippedChatCompletionMessageToolCall) + .isEqualTo(chatCompletionMessageToolCall) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/CodeBundleTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/CodeBundleTest.kt index b24d1bc6..e3df5465 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/CodeBundleTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/CodeBundleTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -56,4 +58,39 @@ internal class CodeBundleTest { ) assertThat(codeBundle.preview()).contains("preview") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val codeBundle = + CodeBundle.builder() + .bundleId("bundle_id") + .location( + CodeBundle.Location.Experiment.builder() + .evalName("eval_name") + .position( + CodeBundle.Location.Experiment.Position.Type.builder() + .type(CodeBundle.Location.Experiment.Position.Type.InnerType.TASK) + .build() + ) + .type(CodeBundle.Location.Experiment.Type.EXPERIMENT) + .build() + ) + .runtimeContext( + CodeBundle.RuntimeContext.builder() + .runtime(CodeBundle.RuntimeContext.Runtime.NODE) + .version("version") + .build() + ) + .preview("preview") + .build() + + val roundtrippedCodeBundle = + jsonMapper.readValue( + jsonMapper.writeValueAsString(codeBundle), + jacksonTypeRef(), + ) + + assertThat(roundtrippedCodeBundle).isEqualTo(codeBundle) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/CreateApiKeyOutputTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/CreateApiKeyOutputTest.kt index f75c2d79..931c2a7f 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/CreateApiKeyOutputTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/CreateApiKeyOutputTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -30,4 +32,27 @@ internal class CreateApiKeyOutputTest { assertThat(createApiKeyOutput.orgId()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(createApiKeyOutput.userId()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val createApiKeyOutput = + CreateApiKeyOutput.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .key("key") + .name("name") + .previewName("preview_name") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + val roundtrippedCreateApiKeyOutput = + jsonMapper.readValue( + jsonMapper.writeValueAsString(createApiKeyOutput), + jacksonTypeRef(), + ) + + assertThat(roundtrippedCreateApiKeyOutput).isEqualTo(createApiKeyOutput) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponseTest.kt index 22dfda4d..efd9ee0d 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponseTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponseTest.kt @@ -3,6 +3,8 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -66,4 +68,44 @@ internal class CrossObjectInsertResponseTest { .build() ) } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val crossObjectInsertResponse = + CrossObjectInsertResponse.builder() + .dataset( + CrossObjectInsertResponse.Dataset.builder() + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf("row_ids" to listOf("string"))), + ) + .build() + ) + .experiment( + CrossObjectInsertResponse.Experiment.builder() + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf("row_ids" to listOf("string"))), + ) + .build() + ) + .projectLogs( + CrossObjectInsertResponse.ProjectLogs.builder() + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf("row_ids" to listOf("string"))), + ) + .build() + ) + .build() + + val roundtrippedCrossObjectInsertResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(crossObjectInsertResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedCrossObjectInsertResponse).isEqualTo(crossObjectInsertResponse) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DataSummaryTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DataSummaryTest.kt index c7d0aae7..40a33b54 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DataSummaryTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DataSummaryTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -13,4 +15,18 @@ internal class DataSummaryTest { assertThat(dataSummary.totalRecords()).isEqualTo(0L) } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val dataSummary = DataSummary.builder().totalRecords(0L).build() + + val roundtrippedDataSummary = + jsonMapper.readValue( + jsonMapper.writeValueAsString(dataSummary), + jacksonTypeRef(), + ) + + assertThat(roundtrippedDataSummary).isEqualTo(dataSummary) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetEventTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetEventTest.kt index 187ec07a..de13fd72 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetEventTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetEventTest.kt @@ -3,6 +3,8 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat @@ -62,4 +64,41 @@ internal class DatasetEventTest { ) assertThat(datasetEvent.tags().getOrNull()).containsExactly("string") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val datasetEvent = + DatasetEvent.builder() + .id("id") + ._xactId("_xact_id") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .rootSpanId("root_span_id") + .spanId("span_id") + .expected(JsonValue.from(mapOf())) + .input(JsonValue.from(mapOf())) + .isRoot(true) + .metadata(DatasetEvent.Metadata.builder().model("model").build()) + .origin( + ObjectReference.builder() + .id("id") + ._xactId("_xact_id") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(ObjectReference.ObjectType.EXPERIMENT) + .created("created") + .build() + ) + .addTag("string") + .build() + + val roundtrippedDatasetEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(datasetEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedDatasetEvent).isEqualTo(datasetEvent) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetTest.kt index 7fd17940..b46ed92a 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetTest.kt @@ -3,6 +3,8 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -41,4 +43,29 @@ internal class DatasetTest { ) assertThat(dataset.userId()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val dataset = + Dataset.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .metadata( + Dataset.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + val roundtrippedDataset = + jsonMapper.readValue(jsonMapper.writeValueAsString(dataset), jacksonTypeRef()) + + assertThat(roundtrippedDataset).isEqualTo(dataset) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarListResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarListResponseTest.kt index 7ffd32f0..d10c2868 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarListResponseTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarListResponseTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -36,4 +38,30 @@ internal class EnvVarListResponseTest { .build() ) } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val envVarListResponse = + EnvVarListResponse.builder() + .addObject( + EnvVar.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(EnvVar.ObjectType.ORGANIZATION) + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .used(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + ) + .build() + + val roundtrippedEnvVarListResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(envVarListResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedEnvVarListResponse).isEqualTo(envVarListResponse) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarTest.kt index f1fa4e2d..f046db47 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/EnvVarTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -27,4 +29,23 @@ internal class EnvVarTest { assertThat(envVar.created()).contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) assertThat(envVar.used()).contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val envVar = + EnvVar.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(EnvVar.ObjectType.ORGANIZATION) + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .used(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + + val roundtrippedEnvVar = + jsonMapper.readValue(jsonMapper.writeValueAsString(envVar), jacksonTypeRef()) + + assertThat(roundtrippedEnvVar).isEqualTo(envVar) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentEventTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentEventTest.kt index d260c428..44c2afc8 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentEventTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentEventTest.kt @@ -3,6 +3,8 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat @@ -122,4 +124,69 @@ internal class ExperimentEventTest { assertThat(experimentEvent.spanParents().getOrNull()).containsExactly("string") assertThat(experimentEvent.tags().getOrNull()).containsExactly("string") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val experimentEvent = + ExperimentEvent.builder() + .id("id") + ._xactId("_xact_id") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .experimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .rootSpanId("root_span_id") + .spanId("span_id") + .context( + ExperimentEvent.Context.builder() + .callerFilename("caller_filename") + .callerFunctionname("caller_functionname") + .callerLineno(0L) + .build() + ) + .error(JsonValue.from(mapOf())) + .expected(JsonValue.from(mapOf())) + .input(JsonValue.from(mapOf())) + .isRoot(true) + .metadata(ExperimentEvent.Metadata.builder().model("model").build()) + .metrics( + ExperimentEvent.Metrics.builder() + .callerFilename(JsonValue.from(mapOf())) + .callerFunctionname(JsonValue.from(mapOf())) + .callerLineno(JsonValue.from(mapOf())) + .completionTokens(0L) + .end(0.0) + .promptTokens(0L) + .start(0.0) + .tokens(0L) + .build() + ) + .origin( + ObjectReference.builder() + .id("id") + ._xactId("_xact_id") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(ObjectReference.ObjectType.EXPERIMENT) + .created("created") + .build() + ) + .output(JsonValue.from(mapOf())) + .scores( + ExperimentEvent.Scores.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .spanAttributes(SpanAttributes.builder().name("name").type(SpanType.LLM).build()) + .addSpanParent("string") + .addTag("string") + .build() + + val roundtrippedExperimentEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(experimentEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedExperimentEvent).isEqualTo(experimentEvent) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentTest.kt index 3d087ff0..551f6fd0 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentTest.kt @@ -3,6 +3,8 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -79,4 +81,50 @@ internal class ExperimentTest { ) assertThat(experiment.userId()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val experiment = + Experiment.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .public_(true) + .baseExpId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .commit("commit") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .datasetVersion("dataset_version") + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .metadata( + Experiment.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .repoInfo( + RepoInfo.builder() + .authorEmail("author_email") + .authorName("author_name") + .branch("branch") + .commit("commit") + .commitMessage("commit_message") + .commitTime("commit_time") + .dirty(true) + .gitDiff("git_diff") + .tag("tag") + .build() + ) + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + val roundtrippedExperiment = + jsonMapper.readValue( + jsonMapper.writeValueAsString(experiment), + jacksonTypeRef(), + ) + + assertThat(roundtrippedExperiment).isEqualTo(experiment) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackDatasetItemTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackDatasetItemTest.kt index 0c0f462c..4018b1b8 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackDatasetItemTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackDatasetItemTest.kt @@ -3,6 +3,8 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -35,4 +37,29 @@ internal class FeedbackDatasetItemTest { assertThat(feedbackDatasetItem.source()).contains(FeedbackDatasetItem.Source.APP) assertThat(feedbackDatasetItem.tags().getOrNull()).containsExactly("string") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val feedbackDatasetItem = + FeedbackDatasetItem.builder() + .id("id") + .comment("comment") + .metadata( + FeedbackDatasetItem.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .source(FeedbackDatasetItem.Source.APP) + .addTag("string") + .build() + + val roundtrippedFeedbackDatasetItem = + jsonMapper.readValue( + jsonMapper.writeValueAsString(feedbackDatasetItem), + jacksonTypeRef(), + ) + + assertThat(roundtrippedFeedbackDatasetItem).isEqualTo(feedbackDatasetItem) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackExperimentItemTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackExperimentItemTest.kt index d776a43a..733c7f31 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackExperimentItemTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackExperimentItemTest.kt @@ -3,6 +3,8 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -49,4 +51,35 @@ internal class FeedbackExperimentItemTest { assertThat(feedbackExperimentItem.source()).contains(FeedbackExperimentItem.Source.APP) assertThat(feedbackExperimentItem.tags().getOrNull()).containsExactly("string") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val feedbackExperimentItem = + FeedbackExperimentItem.builder() + .id("id") + .comment("comment") + .expected(JsonValue.from(mapOf())) + .metadata( + FeedbackExperimentItem.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .scores( + FeedbackExperimentItem.Scores.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .source(FeedbackExperimentItem.Source.APP) + .addTag("string") + .build() + + val roundtrippedFeedbackExperimentItem = + jsonMapper.readValue( + jsonMapper.writeValueAsString(feedbackExperimentItem), + jacksonTypeRef(), + ) + + assertThat(roundtrippedFeedbackExperimentItem).isEqualTo(feedbackExperimentItem) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItemTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItemTest.kt index 7ff09552..91b52fe5 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItemTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItemTest.kt @@ -3,6 +3,8 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -49,4 +51,35 @@ internal class FeedbackProjectLogsItemTest { assertThat(feedbackProjectLogsItem.source()).contains(FeedbackProjectLogsItem.Source.APP) assertThat(feedbackProjectLogsItem.tags().getOrNull()).containsExactly("string") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val feedbackProjectLogsItem = + FeedbackProjectLogsItem.builder() + .id("id") + .comment("comment") + .expected(JsonValue.from(mapOf())) + .metadata( + FeedbackProjectLogsItem.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .scores( + FeedbackProjectLogsItem.Scores.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .source(FeedbackProjectLogsItem.Source.APP) + .addTag("string") + .build() + + val roundtrippedFeedbackProjectLogsItem = + jsonMapper.readValue( + jsonMapper.writeValueAsString(feedbackProjectLogsItem), + jacksonTypeRef(), + ) + + assertThat(roundtrippedFeedbackProjectLogsItem).isEqualTo(feedbackProjectLogsItem) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackResponseSchemaTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackResponseSchemaTest.kt index 6ddb8c4f..f7e73e95 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackResponseSchemaTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FeedbackResponseSchemaTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -14,4 +16,19 @@ internal class FeedbackResponseSchemaTest { assertThat(feedbackResponseSchema.status()).isEqualTo(FeedbackResponseSchema.Status.SUCCESS) } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val feedbackResponseSchema = + FeedbackResponseSchema.builder().status(FeedbackResponseSchema.Status.SUCCESS).build() + + val roundtrippedFeedbackResponseSchema = + jsonMapper.readValue( + jsonMapper.writeValueAsString(feedbackResponseSchema), + jacksonTypeRef(), + ) + + assertThat(roundtrippedFeedbackResponseSchema).isEqualTo(feedbackResponseSchema) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FetchDatasetEventsResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FetchDatasetEventsResponseTest.kt index aeffd433..b61492e2 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FetchDatasetEventsResponseTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FetchDatasetEventsResponseTest.kt @@ -3,6 +3,8 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -69,4 +71,46 @@ internal class FetchDatasetEventsResponseTest { ) assertThat(fetchDatasetEventsResponse.cursor()).contains("cursor") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val fetchDatasetEventsResponse = + FetchDatasetEventsResponse.builder() + .addEvent( + DatasetEvent.builder() + .id("id") + ._xactId("_xact_id") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .rootSpanId("root_span_id") + .spanId("span_id") + .expected(JsonValue.from(mapOf())) + .input(JsonValue.from(mapOf())) + .isRoot(true) + .metadata(DatasetEvent.Metadata.builder().model("model").build()) + .origin( + ObjectReference.builder() + .id("id") + ._xactId("_xact_id") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(ObjectReference.ObjectType.EXPERIMENT) + .created("created") + .build() + ) + .addTag("string") + .build() + ) + .cursor("cursor") + .build() + + val roundtrippedFetchDatasetEventsResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(fetchDatasetEventsResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedFetchDatasetEventsResponse).isEqualTo(fetchDatasetEventsResponse) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FetchExperimentEventsResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FetchExperimentEventsResponseTest.kt index 4d25b839..89e2327e 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FetchExperimentEventsResponseTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FetchExperimentEventsResponseTest.kt @@ -3,6 +3,8 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -129,4 +131,77 @@ internal class FetchExperimentEventsResponseTest { ) assertThat(fetchExperimentEventsResponse.cursor()).contains("cursor") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val fetchExperimentEventsResponse = + FetchExperimentEventsResponse.builder() + .addEvent( + ExperimentEvent.builder() + .id("id") + ._xactId("_xact_id") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .experimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .rootSpanId("root_span_id") + .spanId("span_id") + .context( + ExperimentEvent.Context.builder() + .callerFilename("caller_filename") + .callerFunctionname("caller_functionname") + .callerLineno(0L) + .build() + ) + .error(JsonValue.from(mapOf())) + .expected(JsonValue.from(mapOf())) + .input(JsonValue.from(mapOf())) + .isRoot(true) + .metadata(ExperimentEvent.Metadata.builder().model("model").build()) + .metrics( + ExperimentEvent.Metrics.builder() + .callerFilename(JsonValue.from(mapOf())) + .callerFunctionname(JsonValue.from(mapOf())) + .callerLineno(JsonValue.from(mapOf())) + .completionTokens(0L) + .end(0.0) + .promptTokens(0L) + .start(0.0) + .tokens(0L) + .build() + ) + .origin( + ObjectReference.builder() + .id("id") + ._xactId("_xact_id") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(ObjectReference.ObjectType.EXPERIMENT) + .created("created") + .build() + ) + .output(JsonValue.from(mapOf())) + .scores( + ExperimentEvent.Scores.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .spanAttributes( + SpanAttributes.builder().name("name").type(SpanType.LLM).build() + ) + .addSpanParent("string") + .addTag("string") + .build() + ) + .cursor("cursor") + .build() + + val roundtrippedFetchExperimentEventsResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(fetchExperimentEventsResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedFetchExperimentEventsResponse) + .isEqualTo(fetchExperimentEventsResponse) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FetchProjectLogsEventsResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FetchProjectLogsEventsResponseTest.kt index 600d5ecc..53d51aa5 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FetchProjectLogsEventsResponseTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FetchProjectLogsEventsResponseTest.kt @@ -3,6 +3,8 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -131,4 +133,78 @@ internal class FetchProjectLogsEventsResponseTest { ) assertThat(fetchProjectLogsEventsResponse.cursor()).contains("cursor") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val fetchProjectLogsEventsResponse = + FetchProjectLogsEventsResponse.builder() + .addEvent( + ProjectLogsEvent.builder() + .id("id") + ._xactId("_xact_id") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .logId(ProjectLogsEvent.LogId.G) + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .rootSpanId("root_span_id") + .spanId("span_id") + .context( + ProjectLogsEvent.Context.builder() + .callerFilename("caller_filename") + .callerFunctionname("caller_functionname") + .callerLineno(0L) + .build() + ) + .error(JsonValue.from(mapOf())) + .expected(JsonValue.from(mapOf())) + .input(JsonValue.from(mapOf())) + .isRoot(true) + .metadata(ProjectLogsEvent.Metadata.builder().model("model").build()) + .metrics( + ProjectLogsEvent.Metrics.builder() + .callerFilename(JsonValue.from(mapOf())) + .callerFunctionname(JsonValue.from(mapOf())) + .callerLineno(JsonValue.from(mapOf())) + .completionTokens(0L) + .end(0.0) + .promptTokens(0L) + .start(0.0) + .tokens(0L) + .build() + ) + .origin( + ObjectReference.builder() + .id("id") + ._xactId("_xact_id") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(ObjectReference.ObjectType.EXPERIMENT) + .created("created") + .build() + ) + .output(JsonValue.from(mapOf())) + .scores( + ProjectLogsEvent.Scores.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .spanAttributes( + SpanAttributes.builder().name("name").type(SpanType.LLM).build() + ) + .addSpanParent("string") + .addTag("string") + .build() + ) + .cursor("cursor") + .build() + + val roundtrippedFetchProjectLogsEventsResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(fetchProjectLogsEventsResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedFetchProjectLogsEventsResponse) + .isEqualTo(fetchProjectLogsEventsResponse) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionInvokeResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionInvokeResponseTest.kt index 9dd15f08..e1467ea3 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionInvokeResponseTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionInvokeResponseTest.kt @@ -2,6 +2,9 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test internal class FunctionInvokeResponseTest { @@ -10,4 +13,18 @@ internal class FunctionInvokeResponseTest { fun create() { val functionInvokeResponse = FunctionInvokeResponse.builder().build() } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val functionInvokeResponse = FunctionInvokeResponse.builder().build() + + val roundtrippedFunctionInvokeResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(functionInvokeResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedFunctionInvokeResponse).isEqualTo(functionInvokeResponse) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionTest.kt index a19daa0b..45ecb9f8 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionTest.kt @@ -3,6 +3,8 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat @@ -251,4 +253,134 @@ internal class FunctionTest { ) assertThat(function.tags().getOrNull()).containsExactly("string") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val function = + Function.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + ._xactId("_xact_id") + .functionData( + Function.FunctionData.Prompt.builder() + .type(Function.FunctionData.Prompt.Type.PROMPT) + .build() + ) + .logId(Function.LogId.P) + .name("name") + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .slug("slug") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .functionSchema( + Function.FunctionSchema.builder() + .parameters(JsonValue.from(mapOf())) + .returns(JsonValue.from(mapOf())) + .build() + ) + .functionType(Function.FunctionType.LLM) + .metadata( + Function.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .origin( + Function.Origin.builder() + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(AclObjectType.ORGANIZATION) + .internal_(true) + .build() + ) + .promptData( + PromptData.builder() + .options( + PromptOptions.builder() + .model("model") + .params( + PromptOptions.Params.OpenAIModelParams.builder() + .frequencyPenalty(0.0) + .functionCall( + PromptOptions.Params.OpenAIModelParams.FunctionCall + .UnionMember0 + .AUTO + ) + .maxCompletionTokens(0.0) + .maxTokens(0.0) + .n(0.0) + .presencePenalty(0.0) + .reasoningEffort( + PromptOptions.Params.OpenAIModelParams.ReasoningEffort + .LOW + ) + .responseFormat( + PromptOptions.Params.OpenAIModelParams.ResponseFormat + .JsonObject + .builder() + .type( + PromptOptions.Params.OpenAIModelParams + .ResponseFormat + .JsonObject + .Type + .JSON_OBJECT + ) + .build() + ) + .addStop("string") + .temperature(0.0) + .toolChoice( + PromptOptions.Params.OpenAIModelParams.ToolChoice + .UnionMember0 + .AUTO + ) + .topP(0.0) + .useCache(true) + .build() + ) + .position("position") + .build() + ) + .origin( + PromptData.Origin.builder() + .projectId("project_id") + .promptId("prompt_id") + .promptVersion("prompt_version") + .build() + ) + .parser( + PromptData.Parser.builder() + .choiceScores( + PromptData.Parser.ChoiceScores.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .type(PromptData.Parser.Type.LLM_CLASSIFIER) + .useCot(true) + .build() + ) + .prompt( + PromptData.Prompt.Completion.builder() + .content("content") + .type(PromptData.Prompt.Completion.Type.COMPLETION) + .build() + ) + .addToolFunction( + PromptData.ToolFunction.Function.builder() + .id("id") + .type(PromptData.ToolFunction.Function.Type.FUNCTION) + .build() + ) + .build() + ) + .addTag("string") + .build() + + val roundtrippedFunction = + jsonMapper.readValue( + jsonMapper.writeValueAsString(function), + jacksonTypeRef(), + ) + + assertThat(roundtrippedFunction).isEqualTo(function) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupTest.kt index d2909368..1f75b26f 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat @@ -36,4 +38,26 @@ internal class GroupTest { .containsExactly("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(group.userId()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val group = + Group.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .addMemberGroup("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addMemberUser("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + val roundtrippedGroup = + jsonMapper.readValue(jsonMapper.writeValueAsString(group), jacksonTypeRef()) + + assertThat(roundtrippedGroup).isEqualTo(group) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertDatasetEventTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertDatasetEventTest.kt index a1dd7541..77302d95 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertDatasetEventTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertDatasetEventTest.kt @@ -3,6 +3,8 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat @@ -64,4 +66,42 @@ internal class InsertDatasetEventTest { assertThat(insertDatasetEvent.spanParents().getOrNull()).containsExactly("string") assertThat(insertDatasetEvent.tags().getOrNull()).containsExactly("string") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val insertDatasetEvent = + InsertDatasetEvent.builder() + .id("id") + ._isMerge(true) + .addMergePath(listOf("string")) + ._objectDelete(true) + ._parentId("_parent_id") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .expected(JsonValue.from(mapOf())) + .input(JsonValue.from(mapOf())) + .metadata(InsertDatasetEvent.Metadata.builder().model("model").build()) + .origin( + ObjectReference.builder() + .id("id") + ._xactId("_xact_id") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(ObjectReference.ObjectType.EXPERIMENT) + .created("created") + .build() + ) + .rootSpanId("root_span_id") + .spanId("span_id") + .addSpanParent("string") + .addTag("string") + .build() + + val roundtrippedInsertDatasetEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(insertDatasetEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedInsertDatasetEvent).isEqualTo(insertDatasetEvent) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertEventsResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertEventsResponseTest.kt index 538b7e72..560e7fd1 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertEventsResponseTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertEventsResponseTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -13,4 +15,18 @@ internal class InsertEventsResponseTest { assertThat(insertEventsResponse.rowIds()).containsExactly("string") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val insertEventsResponse = InsertEventsResponse.builder().addRowId("string").build() + + val roundtrippedInsertEventsResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(insertEventsResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedInsertEventsResponse).isEqualTo(insertEventsResponse) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertExperimentEventTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertExperimentEventTest.kt index 9f0a6ed9..c56170f1 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertExperimentEventTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertExperimentEventTest.kt @@ -3,6 +3,8 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat @@ -124,4 +126,69 @@ internal class InsertExperimentEventTest { assertThat(insertExperimentEvent.spanParents().getOrNull()).containsExactly("string") assertThat(insertExperimentEvent.tags().getOrNull()).containsExactly("string") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val insertExperimentEvent = + InsertExperimentEvent.builder() + .id("id") + ._isMerge(true) + .addMergePath(listOf("string")) + ._objectDelete(true) + ._parentId("_parent_id") + .context( + InsertExperimentEvent.Context.builder() + .callerFilename("caller_filename") + .callerFunctionname("caller_functionname") + .callerLineno(0L) + .build() + ) + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .error(JsonValue.from(mapOf())) + .expected(JsonValue.from(mapOf())) + .input(JsonValue.from(mapOf())) + .metadata(InsertExperimentEvent.Metadata.builder().model("model").build()) + .metrics( + InsertExperimentEvent.Metrics.builder() + .callerFilename(JsonValue.from(mapOf())) + .callerFunctionname(JsonValue.from(mapOf())) + .callerLineno(JsonValue.from(mapOf())) + .completionTokens(0L) + .end(0.0) + .promptTokens(0L) + .start(0.0) + .tokens(0L) + .build() + ) + .origin( + ObjectReference.builder() + .id("id") + ._xactId("_xact_id") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(ObjectReference.ObjectType.EXPERIMENT) + .created("created") + .build() + ) + .output(JsonValue.from(mapOf())) + .rootSpanId("root_span_id") + .scores( + InsertExperimentEvent.Scores.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .spanAttributes(SpanAttributes.builder().name("name").type(SpanType.LLM).build()) + .spanId("span_id") + .addSpanParent("string") + .addTag("string") + .build() + + val roundtrippedInsertExperimentEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(insertExperimentEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedInsertExperimentEvent).isEqualTo(insertExperimentEvent) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertProjectLogsEventTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertProjectLogsEventTest.kt index 76148f90..5320624c 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertProjectLogsEventTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/InsertProjectLogsEventTest.kt @@ -3,6 +3,8 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat @@ -124,4 +126,69 @@ internal class InsertProjectLogsEventTest { assertThat(insertProjectLogsEvent.spanParents().getOrNull()).containsExactly("string") assertThat(insertProjectLogsEvent.tags().getOrNull()).containsExactly("string") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val insertProjectLogsEvent = + InsertProjectLogsEvent.builder() + .id("id") + ._isMerge(true) + .addMergePath(listOf("string")) + ._objectDelete(true) + ._parentId("_parent_id") + .context( + InsertProjectLogsEvent.Context.builder() + .callerFilename("caller_filename") + .callerFunctionname("caller_functionname") + .callerLineno(0L) + .build() + ) + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .error(JsonValue.from(mapOf())) + .expected(JsonValue.from(mapOf())) + .input(JsonValue.from(mapOf())) + .metadata(InsertProjectLogsEvent.Metadata.builder().model("model").build()) + .metrics( + InsertProjectLogsEvent.Metrics.builder() + .callerFilename(JsonValue.from(mapOf())) + .callerFunctionname(JsonValue.from(mapOf())) + .callerLineno(JsonValue.from(mapOf())) + .completionTokens(0L) + .end(0.0) + .promptTokens(0L) + .start(0.0) + .tokens(0L) + .build() + ) + .origin( + ObjectReference.builder() + .id("id") + ._xactId("_xact_id") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(ObjectReference.ObjectType.EXPERIMENT) + .created("created") + .build() + ) + .output(JsonValue.from(mapOf())) + .rootSpanId("root_span_id") + .scores( + InsertProjectLogsEvent.Scores.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .spanAttributes(SpanAttributes.builder().name("name").type(SpanType.LLM).build()) + .spanId("span_id") + .addSpanParent("string") + .addTag("string") + .build() + + val roundtrippedInsertProjectLogsEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(insertProjectLogsEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedInsertProjectLogsEvent).isEqualTo(insertProjectLogsEvent) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/MetricSummaryTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/MetricSummaryTest.kt index c7c267e4..e236bd38 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/MetricSummaryTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/MetricSummaryTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -26,4 +28,26 @@ internal class MetricSummaryTest { assertThat(metricSummary.unit()).isEqualTo("unit") assertThat(metricSummary.diff()).contains(0.0) } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val metricSummary = + MetricSummary.builder() + .improvements(0L) + .metric(0.0) + .name("name") + .regressions(0L) + .unit("unit") + .diff(0.0) + .build() + + val roundtrippedMetricSummary = + jsonMapper.readValue( + jsonMapper.writeValueAsString(metricSummary), + jacksonTypeRef(), + ) + + assertThat(roundtrippedMetricSummary).isEqualTo(metricSummary) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ObjectReferenceTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ObjectReferenceTest.kt index 10bd75a5..80d4a6e0 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ObjectReferenceTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ObjectReferenceTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -24,4 +26,25 @@ internal class ObjectReferenceTest { assertThat(objectReference.objectType()).isEqualTo(ObjectReference.ObjectType.EXPERIMENT) assertThat(objectReference.created()).contains("created") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val objectReference = + ObjectReference.builder() + .id("id") + ._xactId("_xact_id") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(ObjectReference.ObjectType.EXPERIMENT) + .created("created") + .build() + + val roundtrippedObjectReference = + jsonMapper.readValue( + jsonMapper.writeValueAsString(objectReference), + jacksonTypeRef(), + ) + + assertThat(roundtrippedObjectReference).isEqualTo(objectReference) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OnlineScoreConfigTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OnlineScoreConfigTest.kt index 556b42d3..9a1a9f83 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OnlineScoreConfigTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OnlineScoreConfigTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -36,4 +38,29 @@ internal class OnlineScoreConfigTest { assertThat(onlineScoreConfig.applyToRootSpan()).contains(true) assertThat(onlineScoreConfig.applyToSpanNames().getOrNull()).containsExactly("string") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val onlineScoreConfig = + OnlineScoreConfig.builder() + .samplingRate(0.0) + .addScorer( + OnlineScoreConfig.Scorer.Function.builder() + .id("id") + .type(OnlineScoreConfig.Scorer.Function.Type.FUNCTION) + .build() + ) + .applyToRootSpan(true) + .addApplyToSpanName("string") + .build() + + val roundtrippedOnlineScoreConfig = + jsonMapper.readValue( + jsonMapper.writeValueAsString(onlineScoreConfig), + jacksonTypeRef(), + ) + + assertThat(roundtrippedOnlineScoreConfig).isEqualTo(onlineScoreConfig) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationTest.kt index 8e7ab68d..83448fde 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -30,4 +32,27 @@ internal class OrganizationTest { assertThat(organization.proxyUrl()).contains("proxy_url") assertThat(organization.realtimeUrl()).contains("realtime_url") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val organization = + Organization.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .apiUrl("api_url") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .isUniversalApi(true) + .proxyUrl("proxy_url") + .realtimeUrl("realtime_url") + .build() + + val roundtrippedOrganization = + jsonMapper.readValue( + jsonMapper.writeValueAsString(organization), + jacksonTypeRef(), + ) + + assertThat(roundtrippedOrganization).isEqualTo(organization) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PatchOrganizationMembersOutputTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PatchOrganizationMembersOutputTest.kt index c25d8575..3afc427b 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PatchOrganizationMembersOutputTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PatchOrganizationMembersOutputTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -21,4 +23,24 @@ internal class PatchOrganizationMembersOutputTest { .isEqualTo(PatchOrganizationMembersOutput.Status.SUCCESS) assertThat(patchOrganizationMembersOutput.sendEmailError()).contains("send_email_error") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val patchOrganizationMembersOutput = + PatchOrganizationMembersOutput.builder() + .orgId("org_id") + .status(PatchOrganizationMembersOutput.Status.SUCCESS) + .sendEmailError("send_email_error") + .build() + + val roundtrippedPatchOrganizationMembersOutput = + jsonMapper.readValue( + jsonMapper.writeValueAsString(patchOrganizationMembersOutput), + jacksonTypeRef(), + ) + + assertThat(roundtrippedPatchOrganizationMembersOutput) + .isEqualTo(patchOrganizationMembersOutput) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogsEventTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogsEventTest.kt index 48cfb3bc..e91f1d39 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogsEventTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectLogsEventTest.kt @@ -3,6 +3,8 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat @@ -124,4 +126,70 @@ internal class ProjectLogsEventTest { assertThat(projectLogsEvent.spanParents().getOrNull()).containsExactly("string") assertThat(projectLogsEvent.tags().getOrNull()).containsExactly("string") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val projectLogsEvent = + ProjectLogsEvent.builder() + .id("id") + ._xactId("_xact_id") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .logId(ProjectLogsEvent.LogId.G) + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .rootSpanId("root_span_id") + .spanId("span_id") + .context( + ProjectLogsEvent.Context.builder() + .callerFilename("caller_filename") + .callerFunctionname("caller_functionname") + .callerLineno(0L) + .build() + ) + .error(JsonValue.from(mapOf())) + .expected(JsonValue.from(mapOf())) + .input(JsonValue.from(mapOf())) + .isRoot(true) + .metadata(ProjectLogsEvent.Metadata.builder().model("model").build()) + .metrics( + ProjectLogsEvent.Metrics.builder() + .callerFilename(JsonValue.from(mapOf())) + .callerFunctionname(JsonValue.from(mapOf())) + .callerLineno(JsonValue.from(mapOf())) + .completionTokens(0L) + .end(0.0) + .promptTokens(0L) + .start(0.0) + .tokens(0L) + .build() + ) + .origin( + ObjectReference.builder() + .id("id") + ._xactId("_xact_id") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(ObjectReference.ObjectType.EXPERIMENT) + .created("created") + .build() + ) + .output(JsonValue.from(mapOf())) + .scores( + ProjectLogsEvent.Scores.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .spanAttributes(SpanAttributes.builder().name("name").type(SpanType.LLM).build()) + .addSpanParent("string") + .addTag("string") + .build() + + val roundtrippedProjectLogsEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(projectLogsEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedProjectLogsEvent).isEqualTo(projectLogsEvent) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreCategoryTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreCategoryTest.kt index 9368c64a..3e4d1ce0 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreCategoryTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreCategoryTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -14,4 +16,18 @@ internal class ProjectScoreCategoryTest { assertThat(projectScoreCategory.name()).isEqualTo("name") assertThat(projectScoreCategory.value()).isEqualTo(0.0) } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val projectScoreCategory = ProjectScoreCategory.builder().name("name").value(0.0).build() + + val roundtrippedProjectScoreCategory = + jsonMapper.readValue( + jsonMapper.writeValueAsString(projectScoreCategory), + jacksonTypeRef(), + ) + + assertThat(roundtrippedProjectScoreCategory).isEqualTo(projectScoreCategory) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreConfigTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreConfigTest.kt index e3a1e013..613487b8 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreConfigTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreConfigTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -45,4 +47,35 @@ internal class ProjectScoreConfigTest { .build() ) } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val projectScoreConfig = + ProjectScoreConfig.builder() + .destination("destination") + .multiSelect(true) + .online( + OnlineScoreConfig.builder() + .samplingRate(0.0) + .addScorer( + OnlineScoreConfig.Scorer.Function.builder() + .id("id") + .type(OnlineScoreConfig.Scorer.Function.Type.FUNCTION) + .build() + ) + .applyToRootSpan(true) + .addApplyToSpanName("string") + .build() + ) + .build() + + val roundtrippedProjectScoreConfig = + jsonMapper.readValue( + jsonMapper.writeValueAsString(projectScoreConfig), + jacksonTypeRef(), + ) + + assertThat(roundtrippedProjectScoreConfig).isEqualTo(projectScoreConfig) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreTest.kt index ffeec510..3fc8a833 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -80,4 +82,50 @@ internal class ProjectScoreTest { assertThat(projectScore.description()).contains("description") assertThat(projectScore.position()).contains("position") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val projectScore = + ProjectScore.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .scoreType(ProjectScoreType.SLIDER) + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .categoriesOfCategorical( + listOf(ProjectScoreCategory.builder().name("name").value(0.0).build()) + ) + .config( + ProjectScoreConfig.builder() + .destination("destination") + .multiSelect(true) + .online( + OnlineScoreConfig.builder() + .samplingRate(0.0) + .addScorer( + OnlineScoreConfig.Scorer.Function.builder() + .id("id") + .type(OnlineScoreConfig.Scorer.Function.Type.FUNCTION) + .build() + ) + .applyToRootSpan(true) + .addApplyToSpanName("string") + .build() + ) + .build() + ) + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .position("position") + .build() + + val roundtrippedProjectScore = + jsonMapper.readValue( + jsonMapper.writeValueAsString(projectScore), + jacksonTypeRef(), + ) + + assertThat(roundtrippedProjectScore).isEqualTo(projectScore) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectSettingsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectSettingsTest.kt index 5cfa962c..3d5015d9 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectSettingsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectSettingsTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -37,4 +39,30 @@ internal class ProjectSettingsTest { .build() ) } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val projectSettings = + ProjectSettings.builder() + .baselineExperimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .comparisonKey("comparison_key") + .addSpanFieldOrder( + ProjectSettings.SpanFieldOrder.builder() + .columnId("column_id") + .objectType("object_type") + .position("position") + .layout(ProjectSettings.SpanFieldOrder.Layout.FULL) + .build() + ) + .build() + + val roundtrippedProjectSettings = + jsonMapper.readValue( + jsonMapper.writeValueAsString(projectSettings), + jacksonTypeRef(), + ) + + assertThat(roundtrippedProjectSettings).isEqualTo(projectSettings) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagTest.kt index 80341d14..efeaf87b 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -29,4 +31,27 @@ internal class ProjectTagTest { assertThat(projectTag.created()).contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) assertThat(projectTag.description()).contains("description") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val projectTag = + ProjectTag.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .color("color") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .build() + + val roundtrippedProjectTag = + jsonMapper.readValue( + jsonMapper.writeValueAsString(projectTag), + jacksonTypeRef(), + ) + + assertThat(roundtrippedProjectTag).isEqualTo(projectTag) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTest.kt index 7c374e5d..59c7821f 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -56,4 +58,37 @@ internal class ProjectTest { ) assertThat(project.userId()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val project = + Project.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .settings( + ProjectSettings.builder() + .baselineExperimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .comparisonKey("comparison_key") + .addSpanFieldOrder( + ProjectSettings.SpanFieldOrder.builder() + .columnId("column_id") + .objectType("object_type") + .position("position") + .layout(ProjectSettings.SpanFieldOrder.Layout.FULL) + .build() + ) + .build() + ) + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + val roundtrippedProject = + jsonMapper.readValue(jsonMapper.writeValueAsString(project), jacksonTypeRef()) + + assertThat(roundtrippedProject).isEqualTo(project) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptDataTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptDataTest.kt index 324272f3..97966fac 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptDataTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptDataTest.kt @@ -3,6 +3,8 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -166,4 +168,91 @@ internal class PromptDataTest { ) ) } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val promptData = + PromptData.builder() + .options( + PromptOptions.builder() + .model("model") + .params( + PromptOptions.Params.OpenAIModelParams.builder() + .frequencyPenalty(0.0) + .functionCall( + PromptOptions.Params.OpenAIModelParams.FunctionCall.UnionMember0 + .AUTO + ) + .maxCompletionTokens(0.0) + .maxTokens(0.0) + .n(0.0) + .presencePenalty(0.0) + .reasoningEffort( + PromptOptions.Params.OpenAIModelParams.ReasoningEffort.LOW + ) + .responseFormat( + PromptOptions.Params.OpenAIModelParams.ResponseFormat.JsonObject + .builder() + .type( + PromptOptions.Params.OpenAIModelParams.ResponseFormat + .JsonObject + .Type + .JSON_OBJECT + ) + .build() + ) + .addStop("string") + .temperature(0.0) + .toolChoice( + PromptOptions.Params.OpenAIModelParams.ToolChoice.UnionMember0 + .AUTO + ) + .topP(0.0) + .useCache(true) + .build() + ) + .position("position") + .build() + ) + .origin( + PromptData.Origin.builder() + .projectId("project_id") + .promptId("prompt_id") + .promptVersion("prompt_version") + .build() + ) + .parser( + PromptData.Parser.builder() + .choiceScores( + PromptData.Parser.ChoiceScores.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .type(PromptData.Parser.Type.LLM_CLASSIFIER) + .useCot(true) + .build() + ) + .prompt( + PromptData.Prompt.Completion.builder() + .content("content") + .type(PromptData.Prompt.Completion.Type.COMPLETION) + .build() + ) + .addToolFunction( + PromptData.ToolFunction.Function.builder() + .id("id") + .type(PromptData.ToolFunction.Function.Type.FUNCTION) + .build() + ) + .build() + + val roundtrippedPromptData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(promptData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedPromptData).isEqualTo(promptData) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptOptionsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptOptionsTest.kt index 02303103..46cf6e9a 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptOptionsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptOptionsTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -81,4 +83,52 @@ internal class PromptOptionsTest { ) assertThat(promptOptions.position()).contains("position") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val promptOptions = + PromptOptions.builder() + .model("model") + .params( + PromptOptions.Params.OpenAIModelParams.builder() + .frequencyPenalty(0.0) + .functionCall( + PromptOptions.Params.OpenAIModelParams.FunctionCall.UnionMember0.AUTO + ) + .maxCompletionTokens(0.0) + .maxTokens(0.0) + .n(0.0) + .presencePenalty(0.0) + .reasoningEffort(PromptOptions.Params.OpenAIModelParams.ReasoningEffort.LOW) + .responseFormat( + PromptOptions.Params.OpenAIModelParams.ResponseFormat.JsonObject + .builder() + .type( + PromptOptions.Params.OpenAIModelParams.ResponseFormat.JsonObject + .Type + .JSON_OBJECT + ) + .build() + ) + .addStop("string") + .temperature(0.0) + .toolChoice( + PromptOptions.Params.OpenAIModelParams.ToolChoice.UnionMember0.AUTO + ) + .topP(0.0) + .useCache(true) + .build() + ) + .position("position") + .build() + + val roundtrippedPromptOptions = + jsonMapper.readValue( + jsonMapper.writeValueAsString(promptOptions), + jacksonTypeRef(), + ) + + assertThat(roundtrippedPromptOptions).isEqualTo(promptOptions) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptTest.kt index 80570cb0..0928b7d9 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptTest.kt @@ -3,6 +3,8 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat @@ -210,4 +212,113 @@ internal class PromptTest { ) assertThat(prompt.tags().getOrNull()).containsExactly("string") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val prompt = + Prompt.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + ._xactId("_xact_id") + .logId(Prompt.LogId.P) + .name("name") + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .slug("slug") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .functionType(Prompt.FunctionType.LLM) + .metadata( + Prompt.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .promptData( + PromptData.builder() + .options( + PromptOptions.builder() + .model("model") + .params( + PromptOptions.Params.OpenAIModelParams.builder() + .frequencyPenalty(0.0) + .functionCall( + PromptOptions.Params.OpenAIModelParams.FunctionCall + .UnionMember0 + .AUTO + ) + .maxCompletionTokens(0.0) + .maxTokens(0.0) + .n(0.0) + .presencePenalty(0.0) + .reasoningEffort( + PromptOptions.Params.OpenAIModelParams.ReasoningEffort + .LOW + ) + .responseFormat( + PromptOptions.Params.OpenAIModelParams.ResponseFormat + .JsonObject + .builder() + .type( + PromptOptions.Params.OpenAIModelParams + .ResponseFormat + .JsonObject + .Type + .JSON_OBJECT + ) + .build() + ) + .addStop("string") + .temperature(0.0) + .toolChoice( + PromptOptions.Params.OpenAIModelParams.ToolChoice + .UnionMember0 + .AUTO + ) + .topP(0.0) + .useCache(true) + .build() + ) + .position("position") + .build() + ) + .origin( + PromptData.Origin.builder() + .projectId("project_id") + .promptId("prompt_id") + .promptVersion("prompt_version") + .build() + ) + .parser( + PromptData.Parser.builder() + .choiceScores( + PromptData.Parser.ChoiceScores.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .type(PromptData.Parser.Type.LLM_CLASSIFIER) + .useCot(true) + .build() + ) + .prompt( + PromptData.Prompt.Completion.builder() + .content("content") + .type(PromptData.Prompt.Completion.Type.COMPLETION) + .build() + ) + .addToolFunction( + PromptData.ToolFunction.Function.builder() + .id("id") + .type(PromptData.ToolFunction.Function.Type.FUNCTION) + .build() + ) + .build() + ) + .addTag("string") + .build() + + val roundtrippedPrompt = + jsonMapper.readValue(jsonMapper.writeValueAsString(prompt), jacksonTypeRef()) + + assertThat(roundtrippedPrompt).isEqualTo(prompt) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RepoInfoTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RepoInfoTest.kt index 8903a668..8c8ccdc8 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RepoInfoTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RepoInfoTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -32,4 +34,29 @@ internal class RepoInfoTest { assertThat(repoInfo.gitDiff()).contains("git_diff") assertThat(repoInfo.tag()).contains("tag") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val repoInfo = + RepoInfo.builder() + .authorEmail("author_email") + .authorName("author_name") + .branch("branch") + .commit("commit") + .commitMessage("commit_message") + .commitTime("commit_time") + .dirty(true) + .gitDiff("git_diff") + .tag("tag") + .build() + + val roundtrippedRepoInfo = + jsonMapper.readValue( + jsonMapper.writeValueAsString(repoInfo), + jacksonTypeRef(), + ) + + assertThat(roundtrippedRepoInfo).isEqualTo(repoInfo) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleTest.kt index 2be027f8..d057dcc7 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat @@ -46,4 +48,31 @@ internal class RoleTest { assertThat(role.orgId()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(role.userId()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val role = + Role.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .addMemberPermission( + Role.MemberPermission.builder() + .permission(Permission.CREATE) + .restrictObjectType(AclObjectType.ORGANIZATION) + .build() + ) + .addMemberRole("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + val roundtrippedRole = + jsonMapper.readValue(jsonMapper.writeValueAsString(role), jacksonTypeRef()) + + assertThat(roundtrippedRole).isEqualTo(role) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ScoreSummaryTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ScoreSummaryTest.kt index faca9ae7..163e2608 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ScoreSummaryTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ScoreSummaryTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -24,4 +26,25 @@ internal class ScoreSummaryTest { assertThat(scoreSummary.score()).isEqualTo(0.0) assertThat(scoreSummary.diff()).contains(-1.0) } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val scoreSummary = + ScoreSummary.builder() + .improvements(0L) + .name("name") + .regressions(0L) + .score(0.0) + .diff(-1.0) + .build() + + val roundtrippedScoreSummary = + jsonMapper.readValue( + jsonMapper.writeValueAsString(scoreSummary), + jacksonTypeRef(), + ) + + assertThat(roundtrippedScoreSummary).isEqualTo(scoreSummary) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanAttributesTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanAttributesTest.kt index 9ca72654..30df044a 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanAttributesTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanAttributesTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -14,4 +16,18 @@ internal class SpanAttributesTest { assertThat(spanAttributes.name()).contains("name") assertThat(spanAttributes.type()).contains(SpanType.LLM) } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val spanAttributes = SpanAttributes.builder().name("name").type(SpanType.LLM).build() + + val roundtrippedSpanAttributes = + jsonMapper.readValue( + jsonMapper.writeValueAsString(spanAttributes), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSpanAttributes).isEqualTo(spanAttributes) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIFrameTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIFrameTest.kt index 2cc8a1ea..3c05ea3d 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIFrameTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIFrameTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -34,4 +36,29 @@ internal class SpanIFrameTest { assertThat(spanIFrame.postMessage()).contains(true) assertThat(spanIFrame.userId()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val spanIFrame = + SpanIFrame.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .url("url") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .postMessage(true) + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + val roundtrippedSpanIFrame = + jsonMapper.readValue( + jsonMapper.writeValueAsString(spanIFrame), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSpanIFrame).isEqualTo(spanIFrame) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SummarizeDatasetResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SummarizeDatasetResponseTest.kt index c1c3ded6..58021961 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SummarizeDatasetResponseTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SummarizeDatasetResponseTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -25,4 +27,25 @@ internal class SummarizeDatasetResponseTest { assertThat(summarizeDatasetResponse.dataSummary()) .contains(DataSummary.builder().totalRecords(0L).build()) } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val summarizeDatasetResponse = + SummarizeDatasetResponse.builder() + .datasetName("dataset_name") + .datasetUrl("https://example.com") + .projectName("project_name") + .projectUrl("https://example.com") + .dataSummary(DataSummary.builder().totalRecords(0L).build()) + .build() + + val roundtrippedSummarizeDatasetResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(summarizeDatasetResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSummarizeDatasetResponse).isEqualTo(summarizeDatasetResponse) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SummarizeExperimentResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SummarizeExperimentResponseTest.kt index 7401a661..36badb29 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SummarizeExperimentResponseTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SummarizeExperimentResponseTest.kt @@ -3,6 +3,8 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -94,4 +96,58 @@ internal class SummarizeExperimentResponseTest { .build() ) } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val summarizeExperimentResponse = + SummarizeExperimentResponse.builder() + .experimentName("experiment_name") + .experimentUrl("https://example.com") + .projectName("project_name") + .projectUrl("https://example.com") + .comparisonExperimentName("comparison_experiment_name") + .metrics( + SummarizeExperimentResponse.Metrics.builder() + .putAdditionalProperty( + "foo", + JsonValue.from( + mapOf( + "improvements" to 0, + "metric" to 0, + "name" to "name", + "regressions" to 0, + "unit" to "unit", + "diff" to 0, + ) + ), + ) + .build() + ) + .scores( + SummarizeExperimentResponse.Scores.builder() + .putAdditionalProperty( + "foo", + JsonValue.from( + mapOf( + "improvements" to 0, + "name" to "name", + "regressions" to 0, + "score" to 0, + "diff" to -1, + ) + ), + ) + .build() + ) + .build() + + val roundtrippedSummarizeExperimentResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(summarizeExperimentResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSummarizeExperimentResponse).isEqualTo(summarizeExperimentResponse) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/UserTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/UserTest.kt index e0e2d714..49bab46a 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/UserTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/UserTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -27,4 +29,23 @@ internal class UserTest { assertThat(user.familyName()).contains("family_name") assertThat(user.givenName()).contains("given_name") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val user = + User.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .avatarUrl("avatar_url") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .email("email") + .familyName("family_name") + .givenName("given_name") + .build() + + val roundtrippedUser = + jsonMapper.readValue(jsonMapper.writeValueAsString(user), jacksonTypeRef()) + + assertThat(roundtrippedUser).isEqualTo(user) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDataSearchTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDataSearchTest.kt index f62c7306..5a03bd80 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDataSearchTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDataSearchTest.kt @@ -3,6 +3,8 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -28,4 +30,24 @@ internal class ViewDataSearchTest { assertThat(viewDataSearch.tag().getOrNull()) .containsExactly(JsonValue.from(mapOf())) } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val viewDataSearch = + ViewDataSearch.builder() + .addFilter(JsonValue.from(mapOf())) + .addMatch(JsonValue.from(mapOf())) + .addSort(JsonValue.from(mapOf())) + .addTag(JsonValue.from(mapOf())) + .build() + + val roundtrippedViewDataSearch = + jsonMapper.readValue( + jsonMapper.writeValueAsString(viewDataSearch), + jacksonTypeRef(), + ) + + assertThat(roundtrippedViewDataSearch).isEqualTo(viewDataSearch) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDataTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDataTest.kt index 40def064..28b304e1 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDataTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewDataTest.kt @@ -3,6 +3,8 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -32,4 +34,28 @@ internal class ViewDataTest { .build() ) } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val viewData = + ViewData.builder() + .search( + ViewDataSearch.builder() + .addFilter(JsonValue.from(mapOf())) + .addMatch(JsonValue.from(mapOf())) + .addSort(JsonValue.from(mapOf())) + .addTag(JsonValue.from(mapOf())) + .build() + ) + .build() + + val roundtrippedViewData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(viewData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedViewData).isEqualTo(viewData) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewOptionsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewOptionsTest.kt index 83b7a843..3407df7f 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewOptionsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewOptionsTest.kt @@ -3,6 +3,8 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -46,4 +48,34 @@ internal class ViewOptionsTest { assertThat(viewOptions.layout()).contains("layout") assertThat(viewOptions.rowHeight()).contains("rowHeight") } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val viewOptions = + ViewOptions.builder() + .addColumnOrder("string") + .columnSizing( + ViewOptions.ColumnSizing.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .columnVisibility( + ViewOptions.ColumnVisibility.builder() + .putAdditionalProperty("foo", JsonValue.from(true)) + .build() + ) + .grouping("grouping") + .layout("layout") + .rowHeight("rowHeight") + .build() + + val roundtrippedViewOptions = + jsonMapper.readValue( + jsonMapper.writeValueAsString(viewOptions), + jacksonTypeRef(), + ) + + assertThat(roundtrippedViewOptions).isEqualTo(viewOptions) + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewTest.kt index b5b66680..7dca73f4 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewTest.kt @@ -3,6 +3,8 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -94,4 +96,55 @@ internal class ViewTest { .build() ) } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val view = + View.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(AclObjectType.ORGANIZATION) + .viewType(View.ViewType.PROJECTS) + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .options( + ViewOptions.builder() + .addColumnOrder("string") + .columnSizing( + ViewOptions.ColumnSizing.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .columnVisibility( + ViewOptions.ColumnVisibility.builder() + .putAdditionalProperty("foo", JsonValue.from(true)) + .build() + ) + .grouping("grouping") + .layout("layout") + .rowHeight("rowHeight") + .build() + ) + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .viewData( + ViewData.builder() + .search( + ViewDataSearch.builder() + .addFilter(JsonValue.from(mapOf())) + .addMatch(JsonValue.from(mapOf())) + .addSort(JsonValue.from(mapOf())) + .addTag(JsonValue.from(mapOf())) + .build() + ) + .build() + ) + .build() + + val roundtrippedView = + jsonMapper.readValue(jsonMapper.writeValueAsString(view), jacksonTypeRef()) + + assertThat(roundtrippedView).isEqualTo(view) + } } From 18e83fa6760c968b982b8a63d008d9bfd7084ba3 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 2 Apr 2025 15:24:11 +0000 Subject: [PATCH 22/42] codegen metadata --- .stats.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.stats.yml b/.stats.yml index b047325f..91f6c416 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 110 openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/manugoyal%2Fbraintrust-sdk-f0d64ce0e0efde75f9c171f7f3c3d4a72f00a77abb3bc5a7d65b7be1e715689b.yml openapi_spec_hash: a027e48cc6aea2fab3cbdd38f4081119 -config_hash: d9a5a1c2d71a5cd8deee0f478049efae +config_hash: 1ea10787f4def6c54a53f0e6f776f0a5 From a65987da85db749c526a110d7e624f38becf8fff Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 2 Apr 2025 17:06:55 +0000 Subject: [PATCH 23/42] feat(client): make datetime deserialization more lenient (#177) --- .../braintrustdata/api/core/ObjectMappers.kt | 64 ++++++++++++++++++- .../api/core/ObjectMappersTest.kt | 21 ++++++ 2 files changed, 83 insertions(+), 2 deletions(-) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ObjectMappers.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ObjectMappers.kt index 9e7a7599..c3287a6b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ObjectMappers.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ObjectMappers.kt @@ -4,12 +4,16 @@ package com.braintrustdata.api.core import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.JsonParseException +import com.fasterxml.jackson.core.JsonParser +import com.fasterxml.jackson.databind.DeserializationContext import com.fasterxml.jackson.databind.DeserializationFeature import com.fasterxml.jackson.databind.MapperFeature import com.fasterxml.jackson.databind.SerializationFeature import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.cfg.CoercionAction import com.fasterxml.jackson.databind.cfg.CoercionInputShape +import com.fasterxml.jackson.databind.deser.std.StdDeserializer import com.fasterxml.jackson.databind.json.JsonMapper import com.fasterxml.jackson.databind.module.SimpleModule import com.fasterxml.jackson.databind.type.LogicalType @@ -17,13 +21,23 @@ import com.fasterxml.jackson.datatype.jdk8.Jdk8Module import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule import com.fasterxml.jackson.module.kotlin.kotlinModule import java.io.InputStream +import java.time.DateTimeException +import java.time.LocalDate +import java.time.LocalDateTime +import java.time.ZonedDateTime +import java.time.format.DateTimeFormatter +import java.time.temporal.ChronoField fun jsonMapper(): JsonMapper = JsonMapper.builder() .addModule(kotlinModule()) .addModule(Jdk8Module()) .addModule(JavaTimeModule()) - .addModule(SimpleModule().addSerializer(InputStreamJsonSerializer)) + .addModule( + SimpleModule() + .addSerializer(InputStreamSerializer) + .addDeserializer(LocalDateTime::class.java, LenientLocalDateTimeDeserializer()) + ) .withCoercionConfig(LogicalType.Boolean) { it.setCoercion(CoercionInputShape.Integer, CoercionAction.Fail) .setCoercion(CoercionInputShape.Float, CoercionAction.Fail) @@ -91,7 +105,10 @@ fun jsonMapper(): JsonMapper = .disable(MapperFeature.AUTO_DETECT_SETTERS) .build() -private object InputStreamJsonSerializer : BaseSerializer(InputStream::class) { +/** A serializer that serializes [InputStream] to bytes. */ +private object InputStreamSerializer : BaseSerializer(InputStream::class) { + + private fun readResolve(): Any = InputStreamSerializer override fun serialize( value: InputStream?, @@ -105,3 +122,46 @@ private object InputStreamJsonSerializer : BaseSerializer(InputStre } } } + +/** + * A deserializer that can deserialize [LocalDateTime] from datetimes, dates, and zoned datetimes. + */ +private class LenientLocalDateTimeDeserializer : + StdDeserializer(LocalDateTime::class.java) { + + companion object { + + private val DATE_TIME_FORMATTERS = + listOf( + DateTimeFormatter.ISO_LOCAL_DATE_TIME, + DateTimeFormatter.ISO_LOCAL_DATE, + DateTimeFormatter.ISO_ZONED_DATE_TIME, + ) + } + + override fun logicalType(): LogicalType = LogicalType.DateTime + + override fun deserialize(p: JsonParser, context: DeserializationContext?): LocalDateTime { + val exceptions = mutableListOf() + + for (formatter in DATE_TIME_FORMATTERS) { + try { + val temporal = formatter.parse(p.text) + + return when { + !temporal.isSupported(ChronoField.HOUR_OF_DAY) -> + LocalDate.from(temporal).atStartOfDay() + !temporal.isSupported(ChronoField.OFFSET_SECONDS) -> + LocalDateTime.from(temporal) + else -> ZonedDateTime.from(temporal).toLocalDateTime() + } + } catch (e: DateTimeException) { + exceptions.add(e) + } + } + + throw JsonParseException(p, "Cannot parse `LocalDateTime` from value: ${p.text}").apply { + exceptions.forEach { addSuppressed(it) } + } + } +} diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/ObjectMappersTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/ObjectMappersTest.kt index 921665ce..b1a6e835 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/ObjectMappersTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/ObjectMappersTest.kt @@ -2,10 +2,15 @@ package com.braintrustdata.api.core import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.databind.exc.MismatchedInputException +import com.fasterxml.jackson.module.kotlin.readValue +import java.time.LocalDateTime import kotlin.reflect.KClass import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.catchThrowable import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertDoesNotThrow +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.EnumSource import org.junitpioneer.jupiter.cartesian.CartesianTest internal class ObjectMappersTest { @@ -78,4 +83,20 @@ internal class ObjectMappersTest { assertThat(e).isInstanceOf(MismatchedInputException::class.java) } } + + enum class LenientLocalDateTimeTestCase(val string: String) { + DATE("1998-04-21"), + DATE_TIME("1998-04-21T04:00:00"), + ZONED_DATE_TIME_1("1998-04-21T04:00:00+03:00"), + ZONED_DATE_TIME_2("1998-04-21T04:00:00Z"), + } + + @ParameterizedTest + @EnumSource + fun readLocalDateTime_lenient(testCase: LenientLocalDateTimeTestCase) { + val jsonMapper = jsonMapper() + val json = jsonMapper.writeValueAsString(testCase.string) + + assertDoesNotThrow { jsonMapper().readValue(json) } + } } From a36c0b633511abc41164b82429da85bd0810f732 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 3 Apr 2025 11:46:05 +0000 Subject: [PATCH 24/42] feat(client): expose request body setter and getter (#178) --- .../api/models/AclBatchUpdateParams.kt | 12 +++++++++++- .../braintrustdata/api/models/AclCreateParams.kt | 16 +++++++++++++++- .../braintrustdata/api/models/AclDeleteParams.kt | 3 +-- .../api/models/AclFindAndDeleteParams.kt | 16 +++++++++++++++- .../api/models/AiSecretCreateParams.kt | 16 +++++++++++++++- .../api/models/AiSecretDeleteParams.kt | 3 +-- .../api/models/AiSecretFindAndDeleteParams.kt | 12 +++++++++++- .../api/models/AiSecretReplaceParams.kt | 16 +++++++++++++++- .../api/models/AiSecretUpdateParams.kt | 14 +++++++++++++- .../api/models/ApiKeyCreateParams.kt | 12 +++++++++++- .../api/models/ApiKeyDeleteParams.kt | 3 +-- .../api/models/DatasetCreateParams.kt | 14 +++++++++++++- .../api/models/DatasetDeleteParams.kt | 3 +-- .../api/models/DatasetFeedbackParams.kt | 11 ++++++++++- .../api/models/DatasetFetchPostParams.kt | 16 +++++++++++++++- .../api/models/DatasetInsertParams.kt | 11 ++++++++++- .../api/models/DatasetUpdateParams.kt | 13 ++++++++++++- .../api/models/EnvVarCreateParams.kt | 14 +++++++++++++- .../api/models/EnvVarDeleteParams.kt | 3 +-- .../api/models/EnvVarReplaceParams.kt | 14 +++++++++++++- .../api/models/EnvVarUpdateParams.kt | 12 +++++++++++- .../api/models/EvalCreateParams.kt | 16 +++++++++++++++- .../api/models/ExperimentCreateParams.kt | 16 +++++++++++++++- .../api/models/ExperimentDeleteParams.kt | 3 +-- .../api/models/ExperimentFeedbackParams.kt | 11 ++++++++++- .../api/models/ExperimentFetchPostParams.kt | 16 +++++++++++++++- .../api/models/ExperimentInsertParams.kt | 11 ++++++++++- .../api/models/ExperimentUpdateParams.kt | 16 +++++++++++++++- .../api/models/FunctionCreateParams.kt | 16 +++++++++++++++- .../api/models/FunctionDeleteParams.kt | 3 +-- .../api/models/FunctionInvokeParams.kt | 16 +++++++++++++++- .../api/models/FunctionReplaceParams.kt | 16 +++++++++++++++- .../api/models/FunctionUpdateParams.kt | 16 +++++++++++++++- .../api/models/GroupCreateParams.kt | 16 +++++++++++++++- .../api/models/GroupDeleteParams.kt | 3 +-- .../api/models/GroupReplaceParams.kt | 16 +++++++++++++++- .../api/models/GroupUpdateParams.kt | 16 +++++++++++++++- .../api/models/OrganizationDeleteParams.kt | 3 +-- .../api/models/OrganizationMemberUpdateParams.kt | 14 +++++++++++++- .../api/models/OrganizationUpdateParams.kt | 16 +++++++++++++++- .../api/models/ProjectCreateParams.kt | 12 +++++++++++- .../api/models/ProjectDeleteParams.kt | 3 +-- .../api/models/ProjectLogFeedbackParams.kt | 11 ++++++++++- .../api/models/ProjectLogFetchPostParams.kt | 16 +++++++++++++++- .../api/models/ProjectLogInsertParams.kt | 11 ++++++++++- .../api/models/ProjectScoreCreateParams.kt | 16 +++++++++++++++- .../api/models/ProjectScoreDeleteParams.kt | 3 +-- .../api/models/ProjectScoreReplaceParams.kt | 16 +++++++++++++++- .../api/models/ProjectScoreUpdateParams.kt | 16 +++++++++++++++- .../api/models/ProjectTagCreateParams.kt | 14 +++++++++++++- .../api/models/ProjectTagDeleteParams.kt | 3 +-- .../api/models/ProjectTagReplaceParams.kt | 14 +++++++++++++- .../api/models/ProjectTagUpdateParams.kt | 13 ++++++++++++- .../api/models/ProjectUpdateParams.kt | 12 +++++++++++- .../api/models/PromptCreateParams.kt | 16 +++++++++++++++- .../api/models/PromptDeleteParams.kt | 3 +-- .../api/models/PromptReplaceParams.kt | 16 +++++++++++++++- .../api/models/PromptUpdateParams.kt | 16 +++++++++++++++- .../api/models/RoleCreateParams.kt | 16 +++++++++++++++- .../api/models/RoleDeleteParams.kt | 3 +-- .../api/models/RoleReplaceParams.kt | 16 +++++++++++++++- .../api/models/RoleUpdateParams.kt | 16 +++++++++++++++- .../api/models/SpanIframeCreateParams.kt | 16 +++++++++++++++- .../api/models/SpanIframeDeleteParams.kt | 3 +-- .../api/models/SpanIframeReplaceParams.kt | 16 +++++++++++++++- .../api/models/SpanIframeUpdateParams.kt | 14 +++++++++++++- .../api/models/ViewCreateParams.kt | 16 +++++++++++++++- .../api/models/ViewDeleteParams.kt | 12 +++++++++++- .../api/models/ViewReplaceParams.kt | 16 +++++++++++++++- .../api/models/ViewUpdateParams.kt | 16 +++++++++++++++- 70 files changed, 760 insertions(+), 85 deletions(-) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateParams.kt index 56f17eb3..77e4ed5e 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateParams.kt @@ -107,6 +107,16 @@ private constructor( additionalQueryParams = aclBatchUpdateParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [addAcls] + * - [removeAcls] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** * An ACL grants a certain permission or role to a certain user or group on an object. * @@ -301,7 +311,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclCreateParams.kt index 3577ae1d..c79a535c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclCreateParams.kt @@ -174,6 +174,20 @@ private constructor( additionalQueryParams = aclCreateParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [objectId] + * - [objectType] + * - [groupId] + * - [permission] + * - [restrictObjectType] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** The id of the object the ACL applies to */ fun objectId(objectId: String) = apply { body.objectId(objectId) } @@ -421,7 +435,7 @@ private constructor( AclCreateParams(body.build(), additionalHeaders.build(), additionalQueryParams.build()) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclDeleteParams.kt index 03f89bcb..9b05873d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclDeleteParams.kt @@ -204,8 +204,7 @@ private constructor( ) } - @JvmSynthetic - internal fun _body(): Optional> = + fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) fun _pathParam(index: Int): String = diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParams.kt index d0a760d4..9cc0aeed 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParams.kt @@ -171,6 +171,20 @@ private constructor( additionalQueryParams = aclFindAndDeleteParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [objectId] + * - [objectType] + * - [groupId] + * - [permission] + * - [restrictObjectType] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** The id of the object the ACL applies to */ fun objectId(objectId: String) = apply { body.objectId(objectId) } @@ -422,7 +436,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt index c8affb77..cca399fd 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt @@ -141,6 +141,20 @@ private constructor( additionalQueryParams = aiSecretCreateParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [name] + * - [metadata] + * - [orgName] + * - [secret] + * - [type] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Name of the AI secret */ fun name(name: String) = apply { body.name(name) } @@ -351,7 +365,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretDeleteParams.kt index 903f3bf0..c0e7a074 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretDeleteParams.kt @@ -204,8 +204,7 @@ private constructor( ) } - @JvmSynthetic - internal fun _body(): Optional> = + fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) fun _pathParam(index: Int): String = diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParams.kt index a934bad7..e308eb27 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParams.kt @@ -95,6 +95,16 @@ private constructor( additionalQueryParams = aiSecretFindAndDeleteParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [name] + * - [orgName] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Name of the AI secret */ fun name(name: String) = apply { body.name(name) } @@ -261,7 +271,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt index f7bbd5a4..865fc1f5 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt @@ -141,6 +141,20 @@ private constructor( additionalQueryParams = aiSecretReplaceParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [name] + * - [metadata] + * - [orgName] + * - [secret] + * - [type] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Name of the AI secret */ fun name(name: String) = apply { body.name(name) } @@ -351,7 +365,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt index b09bec37..c1ee0f07 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt @@ -131,6 +131,18 @@ private constructor( /** AiSecret id */ fun aiSecretId(aiSecretId: String) = apply { this.aiSecretId = aiSecretId } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [metadata] + * - [name] + * - [secret] + * - [type] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + fun metadata(metadata: Metadata?) = apply { body.metadata(metadata) } /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ @@ -323,7 +335,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body fun _pathParam(index: Int): String = when (index) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyCreateParams.kt index 45681f9d..1aca2e16 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyCreateParams.kt @@ -98,6 +98,16 @@ private constructor( additionalQueryParams = apiKeyCreateParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [name] + * - [orgName] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Name of the api key. Does not have to be unique */ fun name(name: String) = apply { body.name(name) } @@ -264,7 +274,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParams.kt index b0521f29..908060c2 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParams.kt @@ -204,8 +204,7 @@ private constructor( ) } - @JvmSynthetic - internal fun _body(): Optional> = + fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) fun _pathParam(index: Int): String = diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt index 0c32f64e..b50423d0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt @@ -128,6 +128,18 @@ private constructor( additionalQueryParams = datasetCreateParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [name] + * - [projectId] + * - [description] + * - [metadata] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Name of the dataset. Within a project, dataset names are unique */ fun name(name: String) = apply { body.name(name) } @@ -319,7 +331,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetDeleteParams.kt index ffc87279..c4238c34 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetDeleteParams.kt @@ -204,8 +204,7 @@ private constructor( ) } - @JvmSynthetic - internal fun _body(): Optional> = + fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) fun _pathParam(index: Int): String = diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFeedbackParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFeedbackParams.kt index 1237becd..e313cd08 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFeedbackParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFeedbackParams.kt @@ -89,6 +89,15 @@ private constructor( /** Dataset id */ fun datasetId(datasetId: String) = apply { this.datasetId = datasetId } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [feedback] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** A list of dataset feedback items */ fun feedback(feedback: List) = apply { body.feedback(feedback) } @@ -249,7 +258,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body fun _pathParam(index: Int): String = when (index) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt index 93854768..376b2a0e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt @@ -186,6 +186,20 @@ private constructor( /** Dataset id */ fun datasetId(datasetId: String) = apply { this.datasetId = datasetId } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [cursor] + * - [limit] + * - [maxRootSpanId] + * - [maxXactId] + * - [version] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** * An opaque string to be used as a cursor for the next page of results, in order from * latest to earliest. @@ -453,7 +467,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body fun _pathParam(index: Int): String = when (index) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetInsertParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetInsertParams.kt index a1ac47a6..9156ab3c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetInsertParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetInsertParams.kt @@ -89,6 +89,15 @@ private constructor( /** Dataset id */ fun datasetId(datasetId: String) = apply { this.datasetId = datasetId } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [events] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** A list of dataset events to insert */ fun events(events: List) = apply { body.events(events) } @@ -247,7 +256,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body fun _pathParam(index: Int): String = when (index) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt index ef53de0e..62f60da4 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt @@ -122,6 +122,17 @@ private constructor( /** Dataset id */ fun datasetId(datasetId: String) = apply { this.datasetId = datasetId } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [description] + * - [metadata] + * - [name] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Textual description of the dataset */ fun description(description: String?) = apply { body.description(description) } @@ -304,7 +315,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body fun _pathParam(index: Int): String = when (index) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarCreateParams.kt index 8441ccc6..103df4b0 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarCreateParams.kt @@ -129,6 +129,18 @@ private constructor( additionalQueryParams = envVarCreateParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [name] + * - [objectId] + * - [objectType] + * - [value] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** The name of the environment variable */ fun name(name: String) = apply { body.name(name) } @@ -316,7 +328,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarDeleteParams.kt index 8196496d..9547d21a 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarDeleteParams.kt @@ -204,8 +204,7 @@ private constructor( ) } - @JvmSynthetic - internal fun _body(): Optional> = + fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) fun _pathParam(index: Int): String = diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarReplaceParams.kt index 484eeaf7..aca69060 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarReplaceParams.kt @@ -129,6 +129,18 @@ private constructor( additionalQueryParams = envVarReplaceParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [name] + * - [objectId] + * - [objectType] + * - [value] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** The name of the environment variable */ fun name(name: String) = apply { body.name(name) } @@ -316,7 +328,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarUpdateParams.kt index 1b28c065..06b61836 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarUpdateParams.kt @@ -107,6 +107,16 @@ private constructor( /** EnvVar id */ fun envVarId(envVarId: String) = apply { this.envVarId = envVarId } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [name] + * - [value] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** The name of the environment variable */ fun name(name: String) = apply { body.name(name) } @@ -271,7 +281,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body fun _pathParam(index: Int): String = when (index) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt index 1b5f81ce..0d4d88bb 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt @@ -340,6 +340,20 @@ private constructor( additionalQueryParams = evalCreateParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [data] + * - [projectId] + * - [scores] + * - [task] + * - [baseExperimentId] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** The dataset to use */ fun data(data: Data) = apply { body.data(data) } @@ -832,7 +846,7 @@ private constructor( EvalCreateParams(body.build(), additionalHeaders.build(), additionalQueryParams.build()) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentCreateParams.kt index 521838b0..62812a51 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentCreateParams.kt @@ -221,6 +221,20 @@ private constructor( additionalQueryParams = experimentCreateParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [projectId] + * - [baseExpId] + * - [datasetId] + * - [datasetVersion] + * - [description] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Unique identifier for the project that the experiment belongs under */ fun projectId(projectId: String) = apply { body.projectId(projectId) } @@ -532,7 +546,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentDeleteParams.kt index 6b8f8458..82be2d53 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentDeleteParams.kt @@ -205,8 +205,7 @@ private constructor( ) } - @JvmSynthetic - internal fun _body(): Optional> = + fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) fun _pathParam(index: Int): String = diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParams.kt index b3a8bda1..5c621452 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParams.kt @@ -89,6 +89,15 @@ private constructor( /** Experiment id */ fun experimentId(experimentId: String) = apply { this.experimentId = experimentId } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [feedback] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** A list of experiment feedback items */ fun feedback(feedback: List) = apply { body.feedback(feedback) } @@ -249,7 +258,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body fun _pathParam(index: Int): String = when (index) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParams.kt index 24bd5dfc..55ef9ce7 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParams.kt @@ -186,6 +186,20 @@ private constructor( /** Experiment id */ fun experimentId(experimentId: String) = apply { this.experimentId = experimentId } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [cursor] + * - [limit] + * - [maxRootSpanId] + * - [maxXactId] + * - [version] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** * An opaque string to be used as a cursor for the next page of results, in order from * latest to earliest. @@ -453,7 +467,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body fun _pathParam(index: Int): String = when (index) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentInsertParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentInsertParams.kt index de1db1c2..2112cf67 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentInsertParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentInsertParams.kt @@ -89,6 +89,15 @@ private constructor( /** Experiment id */ fun experimentId(experimentId: String) = apply { this.experimentId = experimentId } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [events] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** A list of experiment events to insert */ fun events(events: List) = apply { body.events(events) } @@ -247,7 +256,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body fun _pathParam(index: Int): String = when (index) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt index c17bf930..e3fe3d86 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt @@ -199,6 +199,20 @@ private constructor( /** Experiment id */ fun experimentId(experimentId: String) = apply { this.experimentId = experimentId } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [baseExpId] + * - [datasetId] + * - [datasetVersion] + * - [description] + * - [metadata] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Id of default base experiment to compare against when viewing this experiment */ fun baseExpId(baseExpId: String?) = apply { body.baseExpId(baseExpId) } @@ -473,7 +487,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body fun _pathParam(index: Int): String = when (index) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionCreateParams.kt index 892a8fb9..2439e725 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionCreateParams.kt @@ -228,6 +228,20 @@ private constructor( additionalQueryParams = functionCreateParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [functionData] + * - [name] + * - [projectId] + * - [slug] + * - [description] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + fun functionData(functionData: FunctionData) = apply { body.functionData(functionData) } /** @@ -526,7 +540,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionDeleteParams.kt index 0e216910..0fe9dab9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionDeleteParams.kt @@ -204,8 +204,7 @@ private constructor( ) } - @JvmSynthetic - internal fun _body(): Optional> = + fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) fun _pathParam(index: Int): String = diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt index 6772e006..1e244554 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt @@ -183,6 +183,20 @@ private constructor( /** Function id */ fun functionId(functionId: String) = apply { this.functionId = functionId } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [expected] + * - [input] + * - [messages] + * - [metadata] + * - [mode] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** The expected output of the function */ fun expected(expected: JsonValue) = apply { body.expected(expected) } @@ -447,7 +461,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body fun _pathParam(index: Int): String = when (index) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionReplaceParams.kt index 54775e95..3e7da53f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionReplaceParams.kt @@ -228,6 +228,20 @@ private constructor( additionalQueryParams = functionReplaceParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [functionData] + * - [name] + * - [projectId] + * - [slug] + * - [description] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + fun functionData(functionData: FunctionData) = apply { body.functionData(functionData) } /** @@ -526,7 +540,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt index dab7e59e..971bca89 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt @@ -164,6 +164,20 @@ private constructor( /** Function id */ fun functionId(functionId: String) = apply { this.functionId = functionId } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [description] + * - [functionData] + * - [name] + * - [promptData] + * - [tags] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Textual description of the prompt */ fun description(description: String?) = apply { body.description(description) } @@ -394,7 +408,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body fun _pathParam(index: Int): String = when (index) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupCreateParams.kt index bbcf346b..893d9218 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupCreateParams.kt @@ -148,6 +148,20 @@ private constructor( additionalQueryParams = groupCreateParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [name] + * - [description] + * - [memberGroups] + * - [memberUsers] + * - [orgName] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Name of the group */ fun name(name: String) = apply { body.name(name) } @@ -383,7 +397,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupDeleteParams.kt index 20966178..95ce78c4 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupDeleteParams.kt @@ -204,8 +204,7 @@ private constructor( ) } - @JvmSynthetic - internal fun _body(): Optional> = + fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) fun _pathParam(index: Int): String = diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupReplaceParams.kt index 24c23202..e53d938c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupReplaceParams.kt @@ -148,6 +148,20 @@ private constructor( additionalQueryParams = groupReplaceParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [name] + * - [description] + * - [memberGroups] + * - [memberUsers] + * - [orgName] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Name of the group */ fun name(name: String) = apply { body.name(name) } @@ -383,7 +397,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupUpdateParams.kt index 852acd26..93b812ad 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupUpdateParams.kt @@ -170,6 +170,20 @@ private constructor( /** Group id */ fun groupId(groupId: String) = apply { this.groupId = groupId } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [addMemberGroups] + * - [addMemberUsers] + * - [description] + * - [name] + * - [removeMemberGroups] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** A list of group IDs to add to the group's inheriting-from set */ fun addMemberGroups(addMemberGroups: List?) = apply { body.addMemberGroups(addMemberGroups) @@ -453,7 +467,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body fun _pathParam(index: Int): String = when (index) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationDeleteParams.kt index 336c55bb..7247f8ec 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationDeleteParams.kt @@ -205,8 +205,7 @@ private constructor( ) } - @JvmSynthetic - internal fun _body(): Optional> = + fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) fun _pathParam(index: Int): String = diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationMemberUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationMemberUpdateParams.kt index 2e350e16..461b106f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationMemberUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationMemberUpdateParams.kt @@ -126,6 +126,18 @@ private constructor( additionalQueryParams = organizationMemberUpdateParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [inviteUsers] + * - [orgId] + * - [orgName] + * - [removeUsers] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Users to invite to the organization */ fun inviteUsers(inviteUsers: InviteUsers?) = apply { body.inviteUsers(inviteUsers) } @@ -326,7 +338,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationUpdateParams.kt index 2112877a..f34af0f5 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationUpdateParams.kt @@ -143,6 +143,20 @@ private constructor( /** Organization id */ fun organizationId(organizationId: String) = apply { this.organizationId = organizationId } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [apiUrl] + * - [isUniversalApi] + * - [name] + * - [proxyUrl] + * - [realtimeUrl] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + fun apiUrl(apiUrl: String?) = apply { body.apiUrl(apiUrl) } /** Alias for calling [Builder.apiUrl] with `apiUrl.orElse(null)`. */ @@ -359,7 +373,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body fun _pathParam(index: Int): String = when (index) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectCreateParams.kt index 5e374566..cbd85fab 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectCreateParams.kt @@ -98,6 +98,16 @@ private constructor( additionalQueryParams = projectCreateParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [name] + * - [orgName] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Name of the project */ fun name(name: String) = apply { body.name(name) } @@ -264,7 +274,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectDeleteParams.kt index e753af7e..1da020c8 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectDeleteParams.kt @@ -204,8 +204,7 @@ private constructor( ) } - @JvmSynthetic - internal fun _body(): Optional> = + fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) fun _pathParam(index: Int): String = diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParams.kt index 14c2dfe1..e8cac1f5 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParams.kt @@ -89,6 +89,15 @@ private constructor( /** Project id */ fun projectId(projectId: String) = apply { this.projectId = projectId } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [feedback] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** A list of project logs feedback items */ fun feedback(feedback: List) = apply { body.feedback(feedback) } @@ -249,7 +258,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body fun _pathParam(index: Int): String = when (index) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParams.kt index dd5bc517..40f597d0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParams.kt @@ -186,6 +186,20 @@ private constructor( /** Project id */ fun projectId(projectId: String) = apply { this.projectId = projectId } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [cursor] + * - [limit] + * - [maxRootSpanId] + * - [maxXactId] + * - [version] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** * An opaque string to be used as a cursor for the next page of results, in order from * latest to earliest. @@ -453,7 +467,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body fun _pathParam(index: Int): String = when (index) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogInsertParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogInsertParams.kt index 285b253b..8ea2f668 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogInsertParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogInsertParams.kt @@ -89,6 +89,15 @@ private constructor( /** Project id */ fun projectId(projectId: String) = apply { this.projectId = projectId } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [events] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** A list of project logs events to insert */ fun events(events: List) = apply { body.events(events) } @@ -247,7 +256,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body fun _pathParam(index: Int): String = when (index) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParams.kt index 676216db..3ddc8813 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParams.kt @@ -168,6 +168,20 @@ private constructor( additionalQueryParams = projectScoreCreateParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [name] + * - [projectId] + * - [scoreType] + * - [categories] + * - [config] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Name of the project score */ fun name(name: String) = apply { body.name(name) } @@ -397,7 +411,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreDeleteParams.kt index b9f17660..e9f282f5 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreDeleteParams.kt @@ -205,8 +205,7 @@ private constructor( ) } - @JvmSynthetic - internal fun _body(): Optional> = + fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) fun _pathParam(index: Int): String = diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParams.kt index 5351084a..3ef235b4 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParams.kt @@ -169,6 +169,20 @@ private constructor( additionalQueryParams = projectScoreReplaceParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [name] + * - [projectId] + * - [scoreType] + * - [categories] + * - [config] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Name of the project score */ fun name(name: String) = apply { body.name(name) } @@ -398,7 +412,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt index a7496897..800a0e3b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt @@ -161,6 +161,20 @@ private constructor( /** ProjectScore id */ fun projectScoreId(projectScoreId: String) = apply { this.projectScoreId = projectScoreId } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [categories] + * - [config] + * - [description] + * - [name] + * - [scoreType] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** For categorical-type project scores, the list of all categories */ fun categories(categories: Categories?) = apply { body.categories(categories) } @@ -383,7 +397,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body fun _pathParam(index: Int): String = when (index) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagCreateParams.kt index 0ad5056c..8239d87c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagCreateParams.kt @@ -127,6 +127,18 @@ private constructor( additionalQueryParams = projectTagCreateParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [name] + * - [projectId] + * - [color] + * - [description] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Name of the project tag */ fun name(name: String) = apply { body.name(name) } @@ -317,7 +329,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagDeleteParams.kt index 94f3669c..bf7c316a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagDeleteParams.kt @@ -205,8 +205,7 @@ private constructor( ) } - @JvmSynthetic - internal fun _body(): Optional> = + fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) fun _pathParam(index: Int): String = diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagReplaceParams.kt index dd1ddb62..8d586be3 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagReplaceParams.kt @@ -128,6 +128,18 @@ private constructor( additionalQueryParams = projectTagReplaceParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [name] + * - [projectId] + * - [color] + * - [description] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Name of the project tag */ fun name(name: String) = apply { body.name(name) } @@ -318,7 +330,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParams.kt index b6c34209..31736f8c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParams.kt @@ -121,6 +121,17 @@ private constructor( /** ProjectTag id */ fun projectTagId(projectTagId: String) = apply { this.projectTagId = projectTagId } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [color] + * - [description] + * - [name] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Color of the tag for the UI */ fun color(color: String?) = apply { body.color(color) } @@ -302,7 +313,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body fun _pathParam(index: Int): String = when (index) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectUpdateParams.kt index e9434a8a..2874460a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectUpdateParams.kt @@ -107,6 +107,16 @@ private constructor( /** Project id */ fun projectId(projectId: String) = apply { this.projectId = projectId } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [name] + * - [settings] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Name of the project */ fun name(name: String?) = apply { body.name(name) } @@ -277,7 +287,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body fun _pathParam(index: Int): String = when (index) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptCreateParams.kt index 5e4f31ed..79da4321 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptCreateParams.kt @@ -174,6 +174,20 @@ private constructor( additionalQueryParams = promptCreateParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [name] + * - [projectId] + * - [slug] + * - [description] + * - [functionType] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Name of the prompt */ fun name(name: String) = apply { body.name(name) } @@ -416,7 +430,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptDeleteParams.kt index 81512eeb..e5a58880 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptDeleteParams.kt @@ -204,8 +204,7 @@ private constructor( ) } - @JvmSynthetic - internal fun _body(): Optional> = + fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) fun _pathParam(index: Int): String = diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptReplaceParams.kt index 1368dcaf..d0e5c0d3 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptReplaceParams.kt @@ -174,6 +174,20 @@ private constructor( additionalQueryParams = promptReplaceParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [name] + * - [projectId] + * - [slug] + * - [description] + * - [functionType] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Name of the prompt */ fun name(name: String) = apply { body.name(name) } @@ -416,7 +430,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt index ba01dab9..7e9edc03 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt @@ -153,6 +153,20 @@ private constructor( /** Prompt id */ fun promptId(promptId: String) = apply { this.promptId = promptId } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [description] + * - [name] + * - [promptData] + * - [slug] + * - [tags] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Textual description of the prompt */ fun description(description: String?) = apply { body.description(description) } @@ -371,7 +385,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body fun _pathParam(index: Int): String = when (index) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleCreateParams.kt index 92863dc8..86557ac1 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleCreateParams.kt @@ -149,6 +149,20 @@ private constructor( additionalQueryParams = roleCreateParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [name] + * - [description] + * - [memberPermissions] + * - [memberRoles] + * - [orgName] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Name of the role */ fun name(name: String) = apply { body.name(name) } @@ -384,7 +398,7 @@ private constructor( RoleCreateParams(body.build(), additionalHeaders.build(), additionalQueryParams.build()) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleDeleteParams.kt index 039de039..596b4e90 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleDeleteParams.kt @@ -204,8 +204,7 @@ private constructor( ) } - @JvmSynthetic - internal fun _body(): Optional> = + fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) fun _pathParam(index: Int): String = diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleReplaceParams.kt index 30262b1e..0a787253 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleReplaceParams.kt @@ -149,6 +149,20 @@ private constructor( additionalQueryParams = roleReplaceParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [name] + * - [description] + * - [memberPermissions] + * - [memberRoles] + * - [orgName] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Name of the role */ fun name(name: String) = apply { body.name(name) } @@ -388,7 +402,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleUpdateParams.kt index 16f9816b..0e650f99 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleUpdateParams.kt @@ -173,6 +173,20 @@ private constructor( /** Role id */ fun roleId(roleId: String) = apply { this.roleId = roleId } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [addMemberPermissions] + * - [addMemberRoles] + * - [description] + * - [name] + * - [removeMemberPermissions] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** A list of permissions to add to the role */ fun addMemberPermissions(addMemberPermissions: List?) = apply { body.addMemberPermissions(addMemberPermissions) @@ -463,7 +477,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body fun _pathParam(index: Int): String = when (index) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeCreateParams.kt index b4640f20..942eeb94 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeCreateParams.kt @@ -144,6 +144,20 @@ private constructor( additionalQueryParams = spanIframeCreateParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [name] + * - [projectId] + * - [url] + * - [description] + * - [postMessage] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Name of the span iframe */ fun name(name: String) = apply { body.name(name) } @@ -357,7 +371,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeDeleteParams.kt index c62ab604..cf73c830 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeDeleteParams.kt @@ -205,8 +205,7 @@ private constructor( ) } - @JvmSynthetic - internal fun _body(): Optional> = + fun _body(): Optional> = Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) fun _pathParam(index: Int): String = diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeReplaceParams.kt index fdc7b73d..d089176c 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeReplaceParams.kt @@ -144,6 +144,20 @@ private constructor( additionalQueryParams = spanIframeReplaceParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [name] + * - [projectId] + * - [url] + * - [description] + * - [postMessage] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Name of the span iframe */ fun name(name: String) = apply { body.name(name) } @@ -357,7 +371,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParams.kt index 30e68c47..bcaab7e6 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParams.kt @@ -137,6 +137,18 @@ private constructor( /** SpanIframe id */ fun spanIframeId(spanIframeId: String) = apply { this.spanIframeId = spanIframeId } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [description] + * - [name] + * - [postMessage] + * - [url] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Textual description of the span iframe */ fun description(description: String?) = apply { body.description(description) } @@ -343,7 +355,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body fun _pathParam(index: Int): String = when (index) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewCreateParams.kt index 581e3acd..2dfdfdb1 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewCreateParams.kt @@ -191,6 +191,20 @@ private constructor( additionalQueryParams = viewCreateParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [name] + * - [objectId] + * - [objectType] + * - [viewType] + * - [deletedAt] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Name of the view */ fun name(name: String) = apply { body.name(name) } @@ -435,7 +449,7 @@ private constructor( ViewCreateParams(body.build(), additionalHeaders.build(), additionalQueryParams.build()) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDeleteParams.kt index d5554c7a..4cde6f81 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDeleteParams.kt @@ -103,6 +103,16 @@ private constructor( /** View id */ fun viewId(viewId: String) = apply { this.viewId = viewId } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [objectId] + * - [objectType] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** The id of the object the view applies to */ fun objectId(objectId: String) = apply { body.objectId(objectId) } @@ -266,7 +276,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body fun _pathParam(index: Int): String = when (index) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewReplaceParams.kt index 8bb91df4..51980717 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewReplaceParams.kt @@ -191,6 +191,20 @@ private constructor( additionalQueryParams = viewReplaceParams.additionalQueryParams.toBuilder() } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [name] + * - [objectId] + * - [objectType] + * - [viewType] + * - [deletedAt] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Name of the view */ fun name(name: String) = apply { body.name(name) } @@ -439,7 +453,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body override fun _headers(): Headers = additionalHeaders diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewUpdateParams.kt index 4f15e5e6..eba7a3d0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewUpdateParams.kt @@ -184,6 +184,20 @@ private constructor( /** View id */ fun viewId(viewId: String) = apply { this.viewId = viewId } + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [objectId] + * - [objectType] + * - [name] + * - [options] + * - [userId] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + /** The id of the object the view applies to */ fun objectId(objectId: String) = apply { body.objectId(objectId) } @@ -420,7 +434,7 @@ private constructor( ) } - @JvmSynthetic internal fun _body(): Body = body + fun _body(): Body = body fun _pathParam(index: Int): String = when (index) { From d32e7e5d3343041c4404178e0ebf48efd02ddc22 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 4 Apr 2025 16:24:37 +0000 Subject: [PATCH 25/42] chore(internal): codegen related update (#179) --- .../kotlin/com/braintrustdata/api/models/EvalCreateParams.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt index 0d4d88bb..a56d88ae 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt @@ -2833,7 +2833,9 @@ private constructor( * * Used for best match union deserialization. */ - @JvmSynthetic internal fun validity(): Int = (data.asKnown().getOrNull()?.size ?: 0) + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { (if (it == null) 0 else 1).toInt() } ?: 0) override fun equals(other: Any?): Boolean { if (this === other) { From 49c0c0af714e2770fe35456a046aff3a1d6759d8 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 4 Apr 2025 16:33:21 +0000 Subject: [PATCH 26/42] perf(client): cached parsed type in `HttpResponseFor` (#180) --- .../com/braintrustdata/api/core/http/HttpResponseFor.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/HttpResponseFor.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/HttpResponseFor.kt index 6cb31fa8..a8b0e532 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/HttpResponseFor.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/HttpResponseFor.kt @@ -11,7 +11,9 @@ interface HttpResponseFor : HttpResponse { internal fun HttpResponse.parseable(parse: () -> T): HttpResponseFor = object : HttpResponseFor { - override fun parse(): T = parse() + private val parsed: T by lazy { parse() } + + override fun parse(): T = parsed override fun statusCode(): Int = this@parseable.statusCode() From 2fca092faa8a4679ff792bfd746f9638a7187ba3 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 4 Apr 2025 23:52:59 +0000 Subject: [PATCH 27/42] chore(internal): swap from `getNullable` to `getOptional` (#181) --- .../com/braintrustdata/api/core/Values.kt | 8 +- .../com/braintrustdata/api/models/AISecret.kt | 12 ++- .../com/braintrustdata/api/models/Acl.kt | 13 ++- .../api/models/AclBatchUpdateParams.kt | 27 +++---- .../api/models/AclCreateParams.kt | 11 ++- .../api/models/AclFindAndDeleteParams.kt | 11 ++- .../braintrustdata/api/models/AclListPage.kt | 2 +- .../api/models/AclListPageAsync.kt | 3 +- .../api/models/AiSecretCreateParams.kt | 8 +- .../api/models/AiSecretFindAndDeleteParams.kt | 2 +- .../api/models/AiSecretListPage.kt | 2 +- .../api/models/AiSecretListPageAsync.kt | 3 +- .../api/models/AiSecretReplaceParams.kt | 8 +- .../api/models/AiSecretUpdateParams.kt | 8 +- .../com/braintrustdata/api/models/ApiKey.kt | 6 +- .../api/models/ApiKeyCreateParams.kt | 2 +- .../api/models/ApiKeyListPage.kt | 2 +- .../api/models/ApiKeyListPageAsync.kt | 3 +- .../models/ChatCompletionContentPartImage.kt | 2 +- .../models/ChatCompletionContentPartText.kt | 2 +- .../braintrustdata/api/models/CodeBundle.kt | 2 +- .../api/models/CreateApiKeyOutput.kt | 6 +- .../api/models/CrossObjectInsertResponse.kt | 8 +- .../com/braintrustdata/api/models/Dataset.kt | 12 ++- .../api/models/DatasetCreateParams.kt | 5 +- .../braintrustdata/api/models/DatasetEvent.kt | 10 +-- .../api/models/DatasetFetchPostParams.kt | 12 ++- .../api/models/DatasetListPage.kt | 2 +- .../api/models/DatasetListPageAsync.kt | 3 +- .../api/models/DatasetUpdateParams.kt | 7 +- .../com/braintrustdata/api/models/EnvVar.kt | 4 +- .../api/models/EnvVarCreateParams.kt | 2 +- .../api/models/EnvVarReplaceParams.kt | 2 +- .../api/models/EnvVarUpdateParams.kt | 2 +- .../api/models/EvalCreateParams.kt | 63 +++++++-------- .../braintrustdata/api/models/Experiment.kt | 23 +++--- .../api/models/ExperimentCreateParams.kt | 22 +++-- .../api/models/ExperimentEvent.kt | 42 +++++----- .../api/models/ExperimentFetchPostParams.kt | 12 ++- .../api/models/ExperimentListPage.kt | 2 +- .../api/models/ExperimentListPageAsync.kt | 3 +- .../api/models/ExperimentUpdateParams.kt | 19 ++--- .../api/models/FeedbackDatasetItem.kt | 8 +- .../api/models/FeedbackExperimentItem.kt | 10 +-- .../api/models/FeedbackProjectLogsItem.kt | 10 +-- .../api/models/FetchDatasetEventsResponse.kt | 2 +- .../models/FetchExperimentEventsResponse.kt | 2 +- .../models/FetchProjectLogsEventsResponse.kt | 2 +- .../com/braintrustdata/api/models/Function.kt | 25 +++--- .../api/models/FunctionCreateParams.kt | 20 ++--- .../api/models/FunctionInvokeParams.kt | 43 +++++----- .../api/models/FunctionListPage.kt | 2 +- .../api/models/FunctionListPageAsync.kt | 3 +- .../api/models/FunctionReplaceParams.kt | 20 ++--- .../api/models/FunctionUpdateParams.kt | 16 ++-- .../com/braintrustdata/api/models/Group.kt | 16 ++-- .../api/models/GroupCreateParams.kt | 11 +-- .../api/models/GroupListPage.kt | 2 +- .../api/models/GroupListPageAsync.kt | 3 +- .../api/models/GroupReplaceParams.kt | 11 +-- .../api/models/GroupUpdateParams.kt | 13 ++- .../api/models/InsertDatasetEvent.kt | 29 +++---- .../api/models/InsertExperimentEvent.kt | 58 ++++++------- .../api/models/InsertProjectLogsEvent.kt | 58 ++++++------- .../api/models/MetricSummary.kt | 2 +- .../api/models/ObjectReference.kt | 2 +- .../api/models/OnlineScoreConfig.kt | 5 +- .../braintrustdata/api/models/Organization.kt | 12 ++- .../api/models/OrganizationListPage.kt | 2 +- .../api/models/OrganizationListPageAsync.kt | 3 +- .../models/OrganizationMemberUpdateParams.kt | 30 +++---- .../api/models/OrganizationUpdateParams.kt | 12 ++- .../models/PatchOrganizationMembersOutput.kt | 3 +- .../com/braintrustdata/api/models/Project.kt | 10 +-- .../api/models/ProjectCreateParams.kt | 2 +- .../api/models/ProjectListPage.kt | 2 +- .../api/models/ProjectListPageAsync.kt | 3 +- .../api/models/ProjectLogFetchPostParams.kt | 12 ++- .../api/models/ProjectLogsEvent.kt | 42 +++++----- .../braintrustdata/api/models/ProjectScore.kt | 12 ++- .../api/models/ProjectScoreConfig.kt | 8 +- .../api/models/ProjectScoreCreateParams.kt | 9 +-- .../api/models/ProjectScoreListPage.kt | 2 +- .../api/models/ProjectScoreListPageAsync.kt | 3 +- .../api/models/ProjectScoreReplaceParams.kt | 9 +-- .../api/models/ProjectScoreUpdateParams.kt | 14 ++-- .../api/models/ProjectSettings.kt | 9 +-- .../braintrustdata/api/models/ProjectTag.kt | 7 +- .../api/models/ProjectTagCreateParams.kt | 5 +- .../api/models/ProjectTagListPage.kt | 2 +- .../api/models/ProjectTagListPageAsync.kt | 3 +- .../api/models/ProjectTagReplaceParams.kt | 5 +- .../api/models/ProjectTagUpdateParams.kt | 7 +- .../api/models/ProjectUpdateParams.kt | 5 +- .../com/braintrustdata/api/models/Prompt.kt | 15 ++-- .../api/models/PromptCreateParams.kt | 11 +-- .../braintrustdata/api/models/PromptData.kt | 51 +++++------- .../api/models/PromptListPage.kt | 2 +- .../api/models/PromptListPageAsync.kt | 3 +- .../api/models/PromptOptions.kt | 81 ++++++++----------- .../api/models/PromptReplaceParams.kt | 11 +-- .../api/models/PromptUpdateParams.kt | 12 ++- .../com/braintrustdata/api/models/RepoInfo.kt | 20 +++-- .../com/braintrustdata/api/models/Role.kt | 19 ++--- .../api/models/RoleCreateParams.kt | 12 ++- .../braintrustdata/api/models/RoleListPage.kt | 2 +- .../api/models/RoleListPageAsync.kt | 3 +- .../api/models/RoleReplaceParams.kt | 12 ++- .../api/models/RoleUpdateParams.kt | 17 ++-- .../braintrustdata/api/models/ScoreSummary.kt | 2 +- .../api/models/SpanAttributes.kt | 4 +- .../braintrustdata/api/models/SpanIFrame.kt | 13 ++- .../api/models/SpanIframeCreateParams.kt | 6 +- .../api/models/SpanIframeListPage.kt | 2 +- .../api/models/SpanIframeListPageAsync.kt | 3 +- .../api/models/SpanIframeReplaceParams.kt | 6 +- .../api/models/SpanIframeUpdateParams.kt | 10 +-- .../api/models/SummarizeDatasetResponse.kt | 3 +- .../api/models/SummarizeExperimentResponse.kt | 6 +- .../com/braintrustdata/api/models/User.kt | 10 +-- .../braintrustdata/api/models/UserListPage.kt | 2 +- .../api/models/UserListPageAsync.kt | 3 +- .../com/braintrustdata/api/models/View.kt | 13 ++- .../api/models/ViewCreateParams.kt | 11 ++- .../com/braintrustdata/api/models/ViewData.kt | 2 +- .../api/models/ViewDataSearch.kt | 8 +- .../braintrustdata/api/models/ViewListPage.kt | 2 +- .../api/models/ViewListPageAsync.kt | 3 +- .../braintrustdata/api/models/ViewOptions.kt | 14 ++-- .../api/models/ViewReplaceParams.kt | 11 ++- .../api/models/ViewUpdateParams.kt | 10 +-- 131 files changed, 623 insertions(+), 796 deletions(-) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Values.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Values.kt index 0cb5f8bf..b24237d3 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Values.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Values.kt @@ -132,11 +132,11 @@ sealed class JsonField { } @JvmSynthetic - internal fun getNullable(name: String): T? = + internal fun getOptional(name: String): Optional<@UnsafeVariance T> = when (this) { - is KnownValue -> value - is JsonMissing -> null - is JsonNull -> null + is KnownValue -> Optional.of(value) + is JsonMissing, + is JsonNull -> Optional.empty() else -> throw BraintrustInvalidDataException("`$name` is invalid, received $this") } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AISecret.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AISecret.kt index 059217c1..f5ad5a1b 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AISecret.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AISecret.kt @@ -80,26 +80,25 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun created(): Optional = Optional.ofNullable(created.getNullable("created")) + fun created(): Optional = created.getOptional("created") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun metadata(): Optional = metadata.getOptional("metadata") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun previewSecret(): Optional = - Optional.ofNullable(previewSecret.getNullable("preview_secret")) + fun previewSecret(): Optional = previewSecret.getOptional("preview_secret") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun type(): Optional = Optional.ofNullable(type.getNullable("type")) + fun type(): Optional = type.getOptional("type") /** * Date of last AI secret update @@ -107,8 +106,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun updatedAt(): Optional = - Optional.ofNullable(updatedAt.getNullable("updated_at")) + fun updatedAt(): Optional = updatedAt.getOptional("updated_at") /** * Returns the raw JSON value of [id]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Acl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Acl.kt index dd4f11ae..34941085 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Acl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Acl.kt @@ -117,7 +117,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun created(): Optional = Optional.ofNullable(created.getNullable("created")) + fun created(): Optional = created.getOptional("created") /** * Id of the group the ACL applies to. Exactly one of `user_id` and `group_id` will be provided @@ -125,7 +125,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun groupId(): Optional = Optional.ofNullable(groupId.getNullable("group_id")) + fun groupId(): Optional = groupId.getOptional("group_id") /** * Permission the ACL grants. Exactly one of `permission` and `role_id` will be provided @@ -133,8 +133,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun permission(): Optional = - Optional.ofNullable(permission.getNullable("permission")) + fun permission(): Optional = permission.getOptional("permission") /** * When setting a permission directly, optionally restricts the permission grant to just the @@ -144,7 +143,7 @@ private constructor( * server responded with an unexpected value). */ fun restrictObjectType(): Optional = - Optional.ofNullable(restrictObjectType.getNullable("restrict_object_type")) + restrictObjectType.getOptional("restrict_object_type") /** * Id of the role the ACL grants. Exactly one of `permission` and `role_id` will be provided @@ -152,7 +151,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun roleId(): Optional = Optional.ofNullable(roleId.getNullable("role_id")) + fun roleId(): Optional = roleId.getOptional("role_id") /** * Id of the user the ACL applies to. Exactly one of `user_id` and `group_id` will be provided @@ -160,7 +159,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) + fun userId(): Optional = userId.getOptional("user_id") /** * Returns the raw JSON value of [id]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateParams.kt index 77e4ed5e..3276e25a 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateParams.kt @@ -347,7 +347,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun addAcls(): Optional> = Optional.ofNullable(addAcls.getNullable("add_acls")) + fun addAcls(): Optional> = addAcls.getOptional("add_acls") /** * An ACL grants a certain permission or role to a certain user or group on an object. @@ -362,8 +362,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun removeAcls(): Optional> = - Optional.ofNullable(removeAcls.getNullable("remove_acls")) + fun removeAcls(): Optional> = removeAcls.getOptional("remove_acls") /** * Returns the raw JSON value of [addAcls]. @@ -647,7 +646,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun groupId(): Optional = Optional.ofNullable(groupId.getNullable("group_id")) + fun groupId(): Optional = groupId.getOptional("group_id") /** * Permission the ACL grants. Exactly one of `permission` and `role_id` will be provided @@ -655,8 +654,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun permission(): Optional = - Optional.ofNullable(permission.getNullable("permission")) + fun permission(): Optional = permission.getOptional("permission") /** * When setting a permission directly, optionally restricts the permission grant to just the @@ -666,7 +664,7 @@ private constructor( * the server responded with an unexpected value). */ fun restrictObjectType(): Optional = - Optional.ofNullable(restrictObjectType.getNullable("restrict_object_type")) + restrictObjectType.getOptional("restrict_object_type") /** * Id of the role the ACL grants. Exactly one of `permission` and `role_id` will be provided @@ -674,7 +672,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun roleId(): Optional = Optional.ofNullable(roleId.getNullable("role_id")) + fun roleId(): Optional = roleId.getOptional("role_id") /** * Id of the user the ACL applies to. Exactly one of `user_id` and `group_id` will be @@ -683,7 +681,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) + fun userId(): Optional = userId.getOptional("user_id") /** * Returns the raw JSON value of [objectId]. @@ -1092,7 +1090,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun groupId(): Optional = Optional.ofNullable(groupId.getNullable("group_id")) + fun groupId(): Optional = groupId.getOptional("group_id") /** * Permission the ACL grants. Exactly one of `permission` and `role_id` will be provided @@ -1100,8 +1098,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun permission(): Optional = - Optional.ofNullable(permission.getNullable("permission")) + fun permission(): Optional = permission.getOptional("permission") /** * When setting a permission directly, optionally restricts the permission grant to just the @@ -1111,7 +1108,7 @@ private constructor( * the server responded with an unexpected value). */ fun restrictObjectType(): Optional = - Optional.ofNullable(restrictObjectType.getNullable("restrict_object_type")) + restrictObjectType.getOptional("restrict_object_type") /** * Id of the role the ACL grants. Exactly one of `permission` and `role_id` will be provided @@ -1119,7 +1116,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun roleId(): Optional = Optional.ofNullable(roleId.getNullable("role_id")) + fun roleId(): Optional = roleId.getOptional("role_id") /** * Id of the user the ACL applies to. Exactly one of `user_id` and `group_id` will be @@ -1128,7 +1125,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) + fun userId(): Optional = userId.getOptional("user_id") /** * Returns the raw JSON value of [objectId]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclCreateParams.kt index c79a535c..88196664 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclCreateParams.kt @@ -514,7 +514,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun groupId(): Optional = Optional.ofNullable(groupId.getNullable("group_id")) + fun groupId(): Optional = groupId.getOptional("group_id") /** * Permission the ACL grants. Exactly one of `permission` and `role_id` will be provided @@ -522,8 +522,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun permission(): Optional = - Optional.ofNullable(permission.getNullable("permission")) + fun permission(): Optional = permission.getOptional("permission") /** * When setting a permission directly, optionally restricts the permission grant to just the @@ -533,7 +532,7 @@ private constructor( * the server responded with an unexpected value). */ fun restrictObjectType(): Optional = - Optional.ofNullable(restrictObjectType.getNullable("restrict_object_type")) + restrictObjectType.getOptional("restrict_object_type") /** * Id of the role the ACL grants. Exactly one of `permission` and `role_id` will be provided @@ -541,7 +540,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun roleId(): Optional = Optional.ofNullable(roleId.getNullable("role_id")) + fun roleId(): Optional = roleId.getOptional("role_id") /** * Id of the user the ACL applies to. Exactly one of `user_id` and `group_id` will be @@ -550,7 +549,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) + fun userId(): Optional = userId.getOptional("user_id") /** * Returns the raw JSON value of [objectId]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParams.kt index 9cc0aeed..05969c71 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParams.kt @@ -515,7 +515,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun groupId(): Optional = Optional.ofNullable(groupId.getNullable("group_id")) + fun groupId(): Optional = groupId.getOptional("group_id") /** * Permission the ACL grants. Exactly one of `permission` and `role_id` will be provided @@ -523,8 +523,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun permission(): Optional = - Optional.ofNullable(permission.getNullable("permission")) + fun permission(): Optional = permission.getOptional("permission") /** * When setting a permission directly, optionally restricts the permission grant to just the @@ -534,7 +533,7 @@ private constructor( * the server responded with an unexpected value). */ fun restrictObjectType(): Optional = - Optional.ofNullable(restrictObjectType.getNullable("restrict_object_type")) + restrictObjectType.getOptional("restrict_object_type") /** * Id of the role the ACL grants. Exactly one of `permission` and `role_id` will be provided @@ -542,7 +541,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun roleId(): Optional = Optional.ofNullable(roleId.getNullable("role_id")) + fun roleId(): Optional = roleId.getOptional("role_id") /** * Id of the user the ACL applies to. Exactly one of `user_id` and `group_id` will be @@ -551,7 +550,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) + fun userId(): Optional = userId.getOptional("user_id") /** * Returns the raw JSON value of [objectId]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt index ef35ed0b..58416bbb 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt @@ -86,7 +86,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt index 09126eb6..e876813a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt @@ -18,6 +18,7 @@ import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor import java.util.function.Predicate +import kotlin.jvm.optionals.getOrNull /** * List out all acls. The acls are sorted by creation date, with the most recently-created acls @@ -88,7 +89,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt index cca399fd..6a4e98f4 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt @@ -404,7 +404,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun metadata(): Optional = metadata.getOptional("metadata") /** * For nearly all users, this parameter should be unnecessary. But in the rare case that @@ -414,7 +414,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) + fun orgName(): Optional = orgName.getOptional("org_name") /** * Secret value. If omitted in a PUT request, the existing secret value will be left intact, @@ -423,13 +423,13 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun secret(): Optional = Optional.ofNullable(secret.getNullable("secret")) + fun secret(): Optional = secret.getOptional("secret") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun type(): Optional = Optional.ofNullable(type.getNullable("type")) + fun type(): Optional = type.getOptional("type") /** * Returns the raw JSON value of [name]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParams.kt index e308eb27..83d28e3b 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParams.kt @@ -306,7 +306,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) + fun orgName(): Optional = orgName.getOptional("org_name") /** * Returns the raw JSON value of [name]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt index ebeef363..51743d35 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt @@ -86,7 +86,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt index 486a136d..a156ff87 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt @@ -18,6 +18,7 @@ import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor import java.util.function.Predicate +import kotlin.jvm.optionals.getOrNull /** * List out all ai_secrets. The ai_secrets are sorted by creation date, with the most @@ -91,7 +92,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt index 865fc1f5..af588655 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt @@ -404,7 +404,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun metadata(): Optional = metadata.getOptional("metadata") /** * For nearly all users, this parameter should be unnecessary. But in the rare case that @@ -414,7 +414,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) + fun orgName(): Optional = orgName.getOptional("org_name") /** * Secret value. If omitted in a PUT request, the existing secret value will be left intact, @@ -423,13 +423,13 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun secret(): Optional = Optional.ofNullable(secret.getNullable("secret")) + fun secret(): Optional = secret.getOptional("secret") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun type(): Optional = Optional.ofNullable(type.getNullable("type")) + fun type(): Optional = type.getOptional("type") /** * Returns the raw JSON value of [name]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt index c1ee0f07..4db720cf 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt @@ -370,7 +370,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun metadata(): Optional = metadata.getOptional("metadata") /** * Name of the AI secret @@ -378,19 +378,19 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun name(): Optional = name.getOptional("name") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun secret(): Optional = Optional.ofNullable(secret.getNullable("secret")) + fun secret(): Optional = secret.getOptional("secret") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun type(): Optional = Optional.ofNullable(type.getNullable("type")) + fun type(): Optional = type.getOptional("type") /** * Returns the raw JSON value of [metadata]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKey.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKey.kt index 8d547ba7..17e11b99 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKey.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKey.kt @@ -71,7 +71,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun created(): Optional = Optional.ofNullable(created.getNullable("created")) + fun created(): Optional = created.getOptional("created") /** * Unique identifier for the organization @@ -79,7 +79,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun orgId(): Optional = Optional.ofNullable(orgId.getNullable("org_id")) + fun orgId(): Optional = orgId.getOptional("org_id") /** * Unique identifier for the user @@ -87,7 +87,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) + fun userId(): Optional = userId.getOptional("user_id") /** * Returns the raw JSON value of [id]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyCreateParams.kt index 1aca2e16..236d29be 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyCreateParams.kt @@ -309,7 +309,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) + fun orgName(): Optional = orgName.getOptional("org_name") /** * Returns the raw JSON value of [name]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt index c1dd8fe5..7405bca0 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt @@ -86,7 +86,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt index 7e2a3041..9c4ee966 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt @@ -18,6 +18,7 @@ import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor import java.util.function.Predicate +import kotlin.jvm.optionals.getOrNull /** * List out all api_keys. The api_keys are sorted by creation date, with the most recently-created @@ -88,7 +89,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImage.kt index 79a02da2..d7fb8bd9 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImage.kt @@ -213,7 +213,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun detail(): Optional = Optional.ofNullable(detail.getNullable("detail")) + fun detail(): Optional = detail.getOptional("detail") /** * Returns the raw JSON value of [url]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartText.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartText.kt index 2edc113c..7452ab93 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartText.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartText.kt @@ -41,7 +41,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun text(): Optional = Optional.ofNullable(text.getNullable("text")) + fun text(): Optional = text.getOptional("text") /** * Returns the raw JSON value of [type]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CodeBundle.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CodeBundle.kt index 25bcd6c5..d547c7a0 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CodeBundle.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CodeBundle.kt @@ -72,7 +72,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun preview(): Optional = Optional.ofNullable(preview.getNullable("preview")) + fun preview(): Optional = preview.getOptional("preview") /** * Returns the raw JSON value of [bundleId]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CreateApiKeyOutput.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CreateApiKeyOutput.kt index aaaeab1f..2cbb41ce 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CreateApiKeyOutput.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CreateApiKeyOutput.kt @@ -81,7 +81,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun created(): Optional = Optional.ofNullable(created.getNullable("created")) + fun created(): Optional = created.getOptional("created") /** * Unique identifier for the organization @@ -89,7 +89,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun orgId(): Optional = Optional.ofNullable(orgId.getNullable("org_id")) + fun orgId(): Optional = orgId.getOptional("org_id") /** * Unique identifier for the user @@ -97,7 +97,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) + fun userId(): Optional = userId.getOptional("user_id") /** * Returns the raw JSON value of [id]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponse.kt index 46377149..e258e247 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponse.kt @@ -42,7 +42,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun dataset(): Optional = Optional.ofNullable(dataset.getNullable("dataset")) + fun dataset(): Optional = dataset.getOptional("dataset") /** * A mapping from experiment id to row ids for inserted `events` @@ -50,8 +50,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun experiment(): Optional = - Optional.ofNullable(experiment.getNullable("experiment")) + fun experiment(): Optional = experiment.getOptional("experiment") /** * A mapping from project id to row ids for inserted `events` @@ -59,8 +58,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun projectLogs(): Optional = - Optional.ofNullable(projectLogs.getNullable("project_logs")) + fun projectLogs(): Optional = projectLogs.getOptional("project_logs") /** * Returns the raw JSON value of [dataset]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Dataset.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Dataset.kt index 585c5c7a..66fafea8 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Dataset.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Dataset.kt @@ -80,7 +80,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun created(): Optional = Optional.ofNullable(created.getNullable("created")) + fun created(): Optional = created.getOptional("created") /** * Date of dataset deletion, or null if the dataset is still active @@ -88,8 +88,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun deletedAt(): Optional = - Optional.ofNullable(deletedAt.getNullable("deleted_at")) + fun deletedAt(): Optional = deletedAt.getOptional("deleted_at") /** * Textual description of the dataset @@ -97,8 +96,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * User-controlled metadata about the dataset @@ -106,7 +104,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun metadata(): Optional = metadata.getOptional("metadata") /** * Identifies the user who created the dataset @@ -114,7 +112,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) + fun userId(): Optional = userId.getOptional("user_id") /** * Returns the raw JSON value of [id]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt index b50423d0..b082caaa 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt @@ -382,8 +382,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * User-controlled metadata about the dataset @@ -391,7 +390,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun metadata(): Optional = metadata.getOptional("metadata") /** * Returns the raw JSON value of [name]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetEvent.kt index 50ea5813..e3b2abfa 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetEvent.kt @@ -152,7 +152,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun isRoot(): Optional = Optional.ofNullable(isRoot.getNullable("is_root")) + fun isRoot(): Optional = isRoot.getOptional("is_root") /** * A dictionary with additional data about the test example, model outputs, or just about @@ -164,7 +164,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun metadata(): Optional = metadata.getOptional("metadata") /** * Indicates the event was copied from another object. @@ -172,7 +172,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun origin(): Optional = Optional.ofNullable(origin.getNullable("origin")) + fun origin(): Optional = origin.getOptional("origin") /** * A list of tags to log @@ -180,7 +180,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) + fun tags(): Optional> = tags.getOptional("tags") /** * Returns the raw JSON value of [id]. @@ -640,7 +640,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun model(): Optional = Optional.ofNullable(model.getNullable("model")) + fun model(): Optional = model.getOptional("model") /** * Returns the raw JSON value of [model]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt index 376b2a0e..6dd48c3a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt @@ -512,7 +512,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun cursor(): Optional = Optional.ofNullable(cursor.getNullable("cursor")) + fun cursor(): Optional = cursor.getOptional("cursor") /** * limit the number of traces fetched @@ -532,7 +532,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun limit(): Optional = Optional.ofNullable(limit.getNullable("limit")) + fun limit(): Optional = limit.getOptional("limit") /** * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor of @@ -549,8 +549,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun maxRootSpanId(): Optional = - Optional.ofNullable(maxRootSpanId.getNullable("max_root_span_id")) + fun maxRootSpanId(): Optional = maxRootSpanId.getOptional("max_root_span_id") /** * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor of @@ -567,8 +566,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun maxXactId(): Optional = - Optional.ofNullable(maxXactId.getNullable("max_xact_id")) + fun maxXactId(): Optional = maxXactId.getOptional("max_xact_id") /** * Retrieve a snapshot of events from a past time @@ -579,7 +577,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun version(): Optional = Optional.ofNullable(version.getNullable("version")) + fun version(): Optional = version.getOptional("version") /** * Returns the raw JSON value of [cursor]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt index 40631053..3a8206b0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt @@ -86,7 +86,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt index 536ed5d0..f8a02f19 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt @@ -18,6 +18,7 @@ import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor import java.util.function.Predicate +import kotlin.jvm.optionals.getOrNull /** * List out all datasets. The datasets are sorted by creation date, with the most recently-created @@ -91,7 +92,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt index 62f60da4..53ef6810 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt @@ -352,8 +352,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * User-controlled metadata about the dataset @@ -361,7 +360,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun metadata(): Optional = metadata.getOptional("metadata") /** * Name of the dataset. Within a project, dataset names are unique @@ -369,7 +368,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun name(): Optional = name.getOptional("name") /** * Returns the raw JSON value of [description]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVar.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVar.kt index 5e49e6ce..6eed845c 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVar.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVar.kt @@ -82,7 +82,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun created(): Optional = Optional.ofNullable(created.getNullable("created")) + fun created(): Optional = created.getOptional("created") /** * Date the environment variable was last used @@ -90,7 +90,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun used(): Optional = Optional.ofNullable(used.getNullable("used")) + fun used(): Optional = used.getOptional("used") /** * Returns the raw JSON value of [id]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarCreateParams.kt index 103df4b0..95f3d594 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarCreateParams.kt @@ -385,7 +385,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun value(): Optional = Optional.ofNullable(value.getNullable("value")) + fun value(): Optional = value.getOptional("value") /** * Returns the raw JSON value of [name]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarReplaceParams.kt index aca69060..10e7bda1 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarReplaceParams.kt @@ -385,7 +385,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun value(): Optional = Optional.ofNullable(value.getNullable("value")) + fun value(): Optional = value.getOptional("value") /** * Returns the raw JSON value of [name]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarUpdateParams.kt index 06b61836..0283dad1 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarUpdateParams.kt @@ -320,7 +320,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun value(): Optional = Optional.ofNullable(value.getNullable("value")) + fun value(): Optional = value.getOptional("value") /** * Returns the raw JSON value of [name]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt index a56d88ae..0583e3ba 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt @@ -973,7 +973,7 @@ private constructor( * the server responded with an unexpected value). */ fun baseExperimentId(): Optional = - Optional.ofNullable(baseExperimentId.getNullable("base_experiment_id")) + baseExperimentId.getOptional("base_experiment_id") /** * An optional experiment name to use as a base. If specified, the new experiment will be @@ -983,7 +983,7 @@ private constructor( * the server responded with an unexpected value). */ fun baseExperimentName(): Optional = - Optional.ofNullable(baseExperimentName.getNullable("base_experiment_name")) + baseExperimentName.getOptional("base_experiment_name") /** * An optional name for the experiment created by this eval. If it conflicts with an @@ -992,8 +992,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun experimentName(): Optional = - Optional.ofNullable(experimentName.getNullable("experiment_name")) + fun experimentName(): Optional = experimentName.getOptional("experiment_name") /** * Optional settings for collecting git metadata. By default, will collect all git metadata @@ -1003,7 +1002,7 @@ private constructor( * the server responded with an unexpected value). */ fun gitMetadataSettings(): Optional = - Optional.ofNullable(gitMetadataSettings.getNullable("git_metadata_settings")) + gitMetadataSettings.getOptional("git_metadata_settings") /** * Whether the experiment should be public. Defaults to false. @@ -1011,7 +1010,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun isPublic(): Optional = Optional.ofNullable(isPublic.getNullable("is_public")) + fun isPublic(): Optional = isPublic.getOptional("is_public") /** * The maximum number of tasks/scorers that will be run concurrently. Defaults to undefined, @@ -1020,8 +1019,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun maxConcurrency(): Optional = - Optional.ofNullable(maxConcurrency.getNullable("max_concurrency")) + fun maxConcurrency(): Optional = maxConcurrency.getOptional("max_concurrency") /** * Optional experiment-level metadata to store about the evaluation. You can later use this @@ -1030,7 +1028,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun metadata(): Optional = metadata.getOptional("metadata") /** * Options for tracing the evaluation @@ -1038,7 +1036,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun parent(): Optional = Optional.ofNullable(parent.getNullable("parent")) + fun parent(): Optional = parent.getOptional("parent") /** * Metadata about the state of the repo when the experiment was created @@ -1046,7 +1044,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun repoInfo(): Optional = Optional.ofNullable(repoInfo.getNullable("repo_info")) + fun repoInfo(): Optional = repoInfo.getOptional("repo_info") /** * Whether to stream the results of the eval. If true, the request will return two events: @@ -1056,7 +1054,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun stream(): Optional = Optional.ofNullable(stream.getNullable("stream")) + fun stream(): Optional = stream.getOptional("stream") /** * The maximum duration, in milliseconds, to run the evaluation. Defaults to undefined, in @@ -1065,7 +1063,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun timeout(): Optional = Optional.ofNullable(timeout.getNullable("timeout")) + fun timeout(): Optional = timeout.getOptional("timeout") /** * The number of times to run the evaluator per input. This is useful for evaluating @@ -1075,8 +1073,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun trialCount(): Optional = - Optional.ofNullable(trialCount.getNullable("trial_count")) + fun trialCount(): Optional = trialCount.getOptional("trial_count") /** * Returns the raw JSON value of [data]. @@ -2024,7 +2021,7 @@ private constructor( * if the server responded with an unexpected value). */ fun _internalBtql(): Optional<_InternalBtql> = - Optional.ofNullable(_internalBtql.getNullable("_internal_btql")) + _internalBtql.getOptional("_internal_btql") /** * Returns the raw JSON value of [datasetId]. @@ -2355,7 +2352,7 @@ private constructor( * if the server responded with an unexpected value). */ fun _internalBtql(): Optional<_InternalBtql> = - Optional.ofNullable(_internalBtql.getNullable("_internal_btql")) + _internalBtql.getOptional("_internal_btql") /** * Returns the raw JSON value of [datasetName]. @@ -3185,7 +3182,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun version(): Optional = Optional.ofNullable(version.getNullable("version")) + fun version(): Optional = version.getOptional("version") /** * Returns the raw JSON value of [functionId]. @@ -3404,7 +3401,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun version(): Optional = Optional.ofNullable(version.getNullable("version")) + fun version(): Optional = version.getOptional("version") /** * Returns the raw JSON value of [projectName]. @@ -3828,7 +3825,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun version(): Optional = Optional.ofNullable(version.getNullable("version")) + fun version(): Optional = version.getOptional("version") /** * Returns the raw JSON value of [promptSessionFunctionId]. @@ -4076,7 +4073,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun name(): Optional = name.getOptional("name") /** * Returns the raw JSON value of [code]. @@ -4639,8 +4636,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun inlinePrompt(): Optional = - Optional.ofNullable(inlinePrompt.getNullable("inline_prompt")) + fun inlinePrompt(): Optional = inlinePrompt.getOptional("inline_prompt") /** * The name of the inline prompt @@ -4648,7 +4644,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun name(): Optional = name.getOptional("name") /** * Returns the raw JSON value of [inlinePrompt]. @@ -5159,7 +5155,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun version(): Optional = Optional.ofNullable(version.getNullable("version")) + fun version(): Optional = version.getOptional("version") /** * Returns the raw JSON value of [functionId]. @@ -5378,7 +5374,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun version(): Optional = Optional.ofNullable(version.getNullable("version")) + fun version(): Optional = version.getOptional("version") /** * Returns the raw JSON value of [projectName]. @@ -5802,7 +5798,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun version(): Optional = Optional.ofNullable(version.getNullable("version")) + fun version(): Optional = version.getOptional("version") /** * Returns the raw JSON value of [promptSessionFunctionId]. @@ -6050,7 +6046,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun name(): Optional = name.getOptional("name") /** * Returns the raw JSON value of [code]. @@ -6613,8 +6609,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun inlinePrompt(): Optional = - Optional.ofNullable(inlinePrompt.getNullable("inline_prompt")) + fun inlinePrompt(): Optional = inlinePrompt.getOptional("inline_prompt") /** * The name of the inline prompt @@ -6622,7 +6617,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun name(): Optional = name.getOptional("name") /** * Returns the raw JSON value of [inlinePrompt]. @@ -6835,7 +6830,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun fields(): Optional> = Optional.ofNullable(fields.getNullable("fields")) + fun fields(): Optional> = fields.getOptional("fields") /** * Returns the raw JSON value of [collect]. @@ -7655,7 +7650,7 @@ private constructor( * if the server responded with an unexpected value). */ fun propagatedEvent(): Optional = - Optional.ofNullable(propagatedEvent.getNullable("propagated_event")) + propagatedEvent.getOptional("propagated_event") /** * Identifiers for the row to to log a subspan under @@ -7663,7 +7658,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun rowIds(): Optional = Optional.ofNullable(rowIds.getNullable("row_ids")) + fun rowIds(): Optional = rowIds.getOptional("row_ids") /** * Returns the raw JSON value of [objectId]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Experiment.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Experiment.kt index 873c1faf..e756f680 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Experiment.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Experiment.kt @@ -121,7 +121,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun baseExpId(): Optional = Optional.ofNullable(baseExpId.getNullable("base_exp_id")) + fun baseExpId(): Optional = baseExpId.getOptional("base_exp_id") /** * Commit, taken directly from `repo_info.commit` @@ -129,7 +129,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun commit(): Optional = Optional.ofNullable(commit.getNullable("commit")) + fun commit(): Optional = commit.getOptional("commit") /** * Date of experiment creation @@ -137,7 +137,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun created(): Optional = Optional.ofNullable(created.getNullable("created")) + fun created(): Optional = created.getOptional("created") /** * Identifier of the linked dataset, or null if the experiment is not linked to a dataset @@ -145,7 +145,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun datasetId(): Optional = Optional.ofNullable(datasetId.getNullable("dataset_id")) + fun datasetId(): Optional = datasetId.getOptional("dataset_id") /** * Version number of the linked dataset the experiment was run against. This can be used to @@ -154,8 +154,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun datasetVersion(): Optional = - Optional.ofNullable(datasetVersion.getNullable("dataset_version")) + fun datasetVersion(): Optional = datasetVersion.getOptional("dataset_version") /** * Date of experiment deletion, or null if the experiment is still active @@ -163,8 +162,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun deletedAt(): Optional = - Optional.ofNullable(deletedAt.getNullable("deleted_at")) + fun deletedAt(): Optional = deletedAt.getOptional("deleted_at") /** * Textual description of the experiment @@ -172,8 +170,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * User-controlled metadata about the experiment @@ -181,7 +178,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun metadata(): Optional = metadata.getOptional("metadata") /** * Metadata about the state of the repo when the experiment was created @@ -189,7 +186,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun repoInfo(): Optional = Optional.ofNullable(repoInfo.getNullable("repo_info")) + fun repoInfo(): Optional = repoInfo.getOptional("repo_info") /** * Identifies the user who created the experiment @@ -197,7 +194,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) + fun userId(): Optional = userId.getOptional("user_id") /** * Returns the raw JSON value of [id]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentCreateParams.kt index 62812a51..f1387ce7 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentCreateParams.kt @@ -623,8 +623,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun baseExpId(): Optional = - Optional.ofNullable(baseExpId.getNullable("base_exp_id")) + fun baseExpId(): Optional = baseExpId.getOptional("base_exp_id") /** * Identifier of the linked dataset, or null if the experiment is not linked to a dataset @@ -632,7 +631,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun datasetId(): Optional = Optional.ofNullable(datasetId.getNullable("dataset_id")) + fun datasetId(): Optional = datasetId.getOptional("dataset_id") /** * Version number of the linked dataset the experiment was run against. This can be used to @@ -641,8 +640,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun datasetVersion(): Optional = - Optional.ofNullable(datasetVersion.getNullable("dataset_version")) + fun datasetVersion(): Optional = datasetVersion.getOptional("dataset_version") /** * Textual description of the experiment @@ -650,8 +648,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * Normally, creating an experiment with the same name as an existing experiment will return @@ -661,8 +658,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun ensureNew(): Optional = - Optional.ofNullable(ensureNew.getNullable("ensure_new")) + fun ensureNew(): Optional = ensureNew.getOptional("ensure_new") /** * User-controlled metadata about the experiment @@ -670,7 +666,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun metadata(): Optional = metadata.getOptional("metadata") /** * Name of the experiment. Within a project, experiment names are unique @@ -678,7 +674,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun name(): Optional = name.getOptional("name") /** * Whether or not the experiment is public. Public experiments can be viewed by anybody @@ -687,7 +683,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun public_(): Optional = Optional.ofNullable(public_.getNullable("public")) + fun public_(): Optional = public_.getOptional("public") /** * Metadata about the state of the repo when the experiment was created @@ -695,7 +691,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun repoInfo(): Optional = Optional.ofNullable(repoInfo.getNullable("repo_info")) + fun repoInfo(): Optional = repoInfo.getOptional("repo_info") /** * Returns the raw JSON value of [projectId]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentEvent.kt index 64e9d1b8..8190a183 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentEvent.kt @@ -172,7 +172,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun context(): Optional = Optional.ofNullable(context.getNullable("context")) + fun context(): Optional = context.getOptional("context") /** The error that occurred, if any. */ @JsonProperty("error") @ExcludeMissing fun _error(): JsonValue = error @@ -201,7 +201,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun isRoot(): Optional = Optional.ofNullable(isRoot.getNullable("is_root")) + fun isRoot(): Optional = isRoot.getOptional("is_root") /** * A dictionary with additional data about the test example, model outputs, or just about @@ -213,7 +213,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun metadata(): Optional = metadata.getOptional("metadata") /** * Metrics are numerical measurements tracking the execution of the code that produced the @@ -223,7 +223,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun metrics(): Optional = Optional.ofNullable(metrics.getNullable("metrics")) + fun metrics(): Optional = metrics.getOptional("metrics") /** * Indicates the event was copied from another object. @@ -231,7 +231,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun origin(): Optional = Optional.ofNullable(origin.getNullable("origin")) + fun origin(): Optional = origin.getOptional("origin") /** * The output of your application, including post-processing (an arbitrary, JSON serializable @@ -254,7 +254,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun scores(): Optional = Optional.ofNullable(scores.getNullable("scores")) + fun scores(): Optional = scores.getOptional("scores") /** * Human-identifying attributes of the span, such as name, type, etc. @@ -262,8 +262,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun spanAttributes(): Optional = - Optional.ofNullable(spanAttributes.getNullable("span_attributes")) + fun spanAttributes(): Optional = spanAttributes.getOptional("span_attributes") /** * An array of the parent `span_ids` of this experiment event. This should be empty for the root @@ -272,8 +271,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun spanParents(): Optional> = - Optional.ofNullable(spanParents.getNullable("span_parents")) + fun spanParents(): Optional> = spanParents.getOptional("span_parents") /** * A list of tags to log @@ -281,7 +279,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) + fun tags(): Optional> = tags.getOptional("tags") /** * Returns the raw JSON value of [id]. @@ -951,8 +949,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun callerFilename(): Optional = - Optional.ofNullable(callerFilename.getNullable("caller_filename")) + fun callerFilename(): Optional = callerFilename.getOptional("caller_filename") /** * The function in code which created the experiment event @@ -961,7 +958,7 @@ private constructor( * the server responded with an unexpected value). */ fun callerFunctionname(): Optional = - Optional.ofNullable(callerFunctionname.getNullable("caller_functionname")) + callerFunctionname.getOptional("caller_functionname") /** * Line of code where the experiment event was created @@ -969,8 +966,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun callerLineno(): Optional = - Optional.ofNullable(callerLineno.getNullable("caller_lineno")) + fun callerLineno(): Optional = callerLineno.getOptional("caller_lineno") /** * Returns the raw JSON value of [callerFilename]. @@ -1209,7 +1205,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun model(): Optional = Optional.ofNullable(model.getNullable("model")) + fun model(): Optional = model.getOptional("model") /** * Returns the raw JSON value of [model]. @@ -1405,8 +1401,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun completionTokens(): Optional = - Optional.ofNullable(completionTokens.getNullable("completion_tokens")) + fun completionTokens(): Optional = completionTokens.getOptional("completion_tokens") /** * A unix timestamp recording when the section of code which produced the experiment event @@ -1415,7 +1410,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun end(): Optional = Optional.ofNullable(end.getNullable("end")) + fun end(): Optional = end.getOptional("end") /** * The number of tokens in the prompt used to generate the experiment event (only set if @@ -1424,8 +1419,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun promptTokens(): Optional = - Optional.ofNullable(promptTokens.getNullable("prompt_tokens")) + fun promptTokens(): Optional = promptTokens.getOptional("prompt_tokens") /** * A unix timestamp recording when the section of code which produced the experiment event @@ -1434,7 +1428,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun start(): Optional = Optional.ofNullable(start.getNullable("start")) + fun start(): Optional = start.getOptional("start") /** * The total number of tokens in the input and output of the experiment event. @@ -1442,7 +1436,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun tokens(): Optional = Optional.ofNullable(tokens.getNullable("tokens")) + fun tokens(): Optional = tokens.getOptional("tokens") /** * Returns the raw JSON value of [completionTokens]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParams.kt index 55ef9ce7..d1c52fb9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParams.kt @@ -512,7 +512,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun cursor(): Optional = Optional.ofNullable(cursor.getNullable("cursor")) + fun cursor(): Optional = cursor.getOptional("cursor") /** * limit the number of traces fetched @@ -532,7 +532,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun limit(): Optional = Optional.ofNullable(limit.getNullable("limit")) + fun limit(): Optional = limit.getOptional("limit") /** * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor of @@ -549,8 +549,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun maxRootSpanId(): Optional = - Optional.ofNullable(maxRootSpanId.getNullable("max_root_span_id")) + fun maxRootSpanId(): Optional = maxRootSpanId.getOptional("max_root_span_id") /** * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor of @@ -567,8 +566,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun maxXactId(): Optional = - Optional.ofNullable(maxXactId.getNullable("max_xact_id")) + fun maxXactId(): Optional = maxXactId.getOptional("max_xact_id") /** * Retrieve a snapshot of events from a past time @@ -579,7 +577,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun version(): Optional = Optional.ofNullable(version.getNullable("version")) + fun version(): Optional = version.getOptional("version") /** * Returns the raw JSON value of [cursor]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt index efcde69a..c6415ba6 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt @@ -89,7 +89,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt index 07c10b10..56589a1b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt @@ -18,6 +18,7 @@ import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor import java.util.function.Predicate +import kotlin.jvm.optionals.getOrNull /** * List out all experiments. The experiments are sorted by creation date, with the most @@ -91,7 +92,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt index e3fe3d86..75600e2e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt @@ -552,8 +552,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun baseExpId(): Optional = - Optional.ofNullable(baseExpId.getNullable("base_exp_id")) + fun baseExpId(): Optional = baseExpId.getOptional("base_exp_id") /** * Identifier of the linked dataset, or null if the experiment is not linked to a dataset @@ -561,7 +560,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun datasetId(): Optional = Optional.ofNullable(datasetId.getNullable("dataset_id")) + fun datasetId(): Optional = datasetId.getOptional("dataset_id") /** * Version number of the linked dataset the experiment was run against. This can be used to @@ -570,8 +569,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun datasetVersion(): Optional = - Optional.ofNullable(datasetVersion.getNullable("dataset_version")) + fun datasetVersion(): Optional = datasetVersion.getOptional("dataset_version") /** * Textual description of the experiment @@ -579,8 +577,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * User-controlled metadata about the experiment @@ -588,7 +585,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun metadata(): Optional = metadata.getOptional("metadata") /** * Name of the experiment. Within a project, experiment names are unique @@ -596,7 +593,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun name(): Optional = name.getOptional("name") /** * Whether or not the experiment is public. Public experiments can be viewed by anybody @@ -605,7 +602,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun public_(): Optional = Optional.ofNullable(public_.getNullable("public")) + fun public_(): Optional = public_.getOptional("public") /** * Metadata about the state of the repo when the experiment was created @@ -613,7 +610,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun repoInfo(): Optional = Optional.ofNullable(repoInfo.getNullable("repo_info")) + fun repoInfo(): Optional = repoInfo.getOptional("repo_info") /** * Returns the raw JSON value of [baseExpId]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackDatasetItem.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackDatasetItem.kt index cd797641..9986ad76 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackDatasetItem.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackDatasetItem.kt @@ -54,7 +54,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun comment(): Optional = Optional.ofNullable(comment.getNullable("comment")) + fun comment(): Optional = comment.getOptional("comment") /** * A dictionary with additional data about the feedback. If you have a `user_id`, you can log it @@ -64,7 +64,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun metadata(): Optional = metadata.getOptional("metadata") /** * The source of the feedback. Must be one of "external" (default), "app", or "api" @@ -72,7 +72,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun source(): Optional = Optional.ofNullable(source.getNullable("source")) + fun source(): Optional = source.getOptional("source") /** * A list of tags to log @@ -80,7 +80,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) + fun tags(): Optional> = tags.getOptional("tags") /** * Returns the raw JSON value of [id]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackExperimentItem.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackExperimentItem.kt index adc61edb..ef903e91 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackExperimentItem.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackExperimentItem.kt @@ -58,7 +58,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun comment(): Optional = Optional.ofNullable(comment.getNullable("comment")) + fun comment(): Optional = comment.getOptional("comment") /** * The ground truth value (an arbitrary, JSON serializable object) that you'd compare to @@ -74,7 +74,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun metadata(): Optional = metadata.getOptional("metadata") /** * A dictionary of numeric values (between 0 and 1) to log. These scores will be merged into the @@ -83,7 +83,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun scores(): Optional = Optional.ofNullable(scores.getNullable("scores")) + fun scores(): Optional = scores.getOptional("scores") /** * The source of the feedback. Must be one of "external" (default), "app", or "api" @@ -91,7 +91,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun source(): Optional = Optional.ofNullable(source.getNullable("source")) + fun source(): Optional = source.getOptional("source") /** * A list of tags to log @@ -99,7 +99,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) + fun tags(): Optional> = tags.getOptional("tags") /** * Returns the raw JSON value of [id]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItem.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItem.kt index 87e56b04..a121b9e5 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItem.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItem.kt @@ -58,7 +58,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun comment(): Optional = Optional.ofNullable(comment.getNullable("comment")) + fun comment(): Optional = comment.getOptional("comment") /** * The ground truth value (an arbitrary, JSON serializable object) that you'd compare to @@ -74,7 +74,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun metadata(): Optional = metadata.getOptional("metadata") /** * A dictionary of numeric values (between 0 and 1) to log. These scores will be merged into the @@ -83,7 +83,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun scores(): Optional = Optional.ofNullable(scores.getNullable("scores")) + fun scores(): Optional = scores.getOptional("scores") /** * The source of the feedback. Must be one of "external" (default), "app", or "api" @@ -91,7 +91,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun source(): Optional = Optional.ofNullable(source.getNullable("source")) + fun source(): Optional = source.getOptional("source") /** * A list of tags to log @@ -99,7 +99,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) + fun tags(): Optional> = tags.getOptional("tags") /** * Returns the raw JSON value of [id]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchDatasetEventsResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchDatasetEventsResponse.kt index 62485d5f..e6658cf9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchDatasetEventsResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchDatasetEventsResponse.kt @@ -51,7 +51,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun cursor(): Optional = Optional.ofNullable(cursor.getNullable("cursor")) + fun cursor(): Optional = cursor.getOptional("cursor") /** * Returns the raw JSON value of [events]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchExperimentEventsResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchExperimentEventsResponse.kt index 12f5cc50..12ee5436 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchExperimentEventsResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchExperimentEventsResponse.kt @@ -51,7 +51,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun cursor(): Optional = Optional.ofNullable(cursor.getNullable("cursor")) + fun cursor(): Optional = cursor.getOptional("cursor") /** * Returns the raw JSON value of [events]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchProjectLogsEventsResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchProjectLogsEventsResponse.kt index 5f35d958..ad177f9c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchProjectLogsEventsResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchProjectLogsEventsResponse.kt @@ -51,7 +51,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun cursor(): Optional = Optional.ofNullable(cursor.getNullable("cursor")) + fun cursor(): Optional = cursor.getOptional("cursor") /** * Returns the raw JSON value of [events]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Function.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Function.kt index c4bc3318..d3a0bb30 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Function.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Function.kt @@ -173,7 +173,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun created(): Optional = Optional.ofNullable(created.getNullable("created")) + fun created(): Optional = created.getOptional("created") /** * Textual description of the prompt @@ -181,8 +181,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * JSON schema for the function's parameters and return type @@ -190,15 +189,13 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun functionSchema(): Optional = - Optional.ofNullable(functionSchema.getNullable("function_schema")) + fun functionSchema(): Optional = functionSchema.getOptional("function_schema") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun functionType(): Optional = - Optional.ofNullable(functionType.getNullable("function_type")) + fun functionType(): Optional = functionType.getOptional("function_type") /** * User-controlled metadata about the prompt @@ -206,13 +203,13 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun metadata(): Optional = metadata.getOptional("metadata") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun origin(): Optional = Optional.ofNullable(origin.getNullable("origin")) + fun origin(): Optional = origin.getOptional("origin") /** * The prompt, model, and its parameters @@ -220,8 +217,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun promptData(): Optional = - Optional.ofNullable(promptData.getNullable("prompt_data")) + fun promptData(): Optional = promptData.getOptional("prompt_data") /** * A list of tags for the prompt @@ -229,7 +225,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) + fun tags(): Optional> = tags.getOptional("tags") /** * Returns the raw JSON value of [id]. @@ -1682,8 +1678,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type (e.g. if the server responded with an unexpected value). */ - fun preview(): Optional = - Optional.ofNullable(preview.getNullable("preview")) + fun preview(): Optional = preview.getOptional("preview") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected @@ -3829,7 +3824,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun internal_(): Optional = Optional.ofNullable(internal_.getNullable("internal")) + fun internal_(): Optional = internal_.getOptional("internal") /** * Returns the raw JSON value of [objectId]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionCreateParams.kt index 2439e725..0e55e810 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionCreateParams.kt @@ -635,8 +635,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * JSON schema for the function's parameters and return type @@ -645,20 +644,19 @@ private constructor( * the server responded with an unexpected value). */ fun functionSchema(): Optional = - Optional.ofNullable(functionSchema.getNullable("function_schema")) + functionSchema.getOptional("function_schema") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun functionType(): Optional = - Optional.ofNullable(functionType.getNullable("function_type")) + fun functionType(): Optional = functionType.getOptional("function_type") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun origin(): Optional = Optional.ofNullable(origin.getNullable("origin")) + fun origin(): Optional = origin.getOptional("origin") /** * The prompt, model, and its parameters @@ -666,8 +664,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun promptData(): Optional = - Optional.ofNullable(promptData.getNullable("prompt_data")) + fun promptData(): Optional = promptData.getOptional("prompt_data") /** * A list of tags for the prompt @@ -675,7 +672,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) + fun tags(): Optional> = tags.getOptional("tags") /** * Returns the raw JSON value of [functionData]. @@ -2004,8 +2001,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type (e.g. if the server responded with an unexpected value). */ - fun preview(): Optional = - Optional.ofNullable(preview.getNullable("preview")) + fun preview(): Optional = preview.getOptional("preview") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected @@ -3927,7 +3923,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun internal_(): Optional = Optional.ofNullable(internal_.getNullable("internal")) + fun internal_(): Optional = internal_.getOptional("internal") /** * Returns the raw JSON value of [objectId]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt index 1e244554..d5512a91 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt @@ -515,8 +515,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun messages(): Optional> = - Optional.ofNullable(messages.getNullable("messages")) + fun messages(): Optional> = messages.getOptional("messages") /** * Any relevant metadata @@ -524,7 +523,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun metadata(): Optional = metadata.getOptional("metadata") /** * The mode format of the returned value (defaults to 'auto') @@ -532,7 +531,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun mode(): Optional = Optional.ofNullable(mode.getNullable("mode")) + fun mode(): Optional = mode.getOptional("mode") /** * Options for tracing the function call @@ -540,7 +539,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun parent(): Optional = Optional.ofNullable(parent.getNullable("parent")) + fun parent(): Optional = parent.getOptional("parent") /** * Whether to stream the response. If true, results will be returned in the Braintrust SSE @@ -549,7 +548,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun stream(): Optional = Optional.ofNullable(stream.getNullable("stream")) + fun stream(): Optional = stream.getOptional("stream") /** * The version of the function @@ -557,7 +556,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun version(): Optional = Optional.ofNullable(version.getNullable("version")) + fun version(): Optional = version.getOptional("version") /** * Returns the raw JSON value of [messages]. @@ -1171,13 +1170,13 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun content(): Optional = Optional.ofNullable(content.getNullable("content")) + fun content(): Optional = content.getOptional("content") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun name(): Optional = name.getOptional("name") /** * Returns the raw JSON value of [role]. @@ -1520,13 +1519,13 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun content(): Optional = Optional.ofNullable(content.getNullable("content")) + fun content(): Optional = content.getOptional("content") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun name(): Optional = name.getOptional("name") /** * Returns the raw JSON value of [role]. @@ -2264,27 +2263,26 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun content(): Optional = Optional.ofNullable(content.getNullable("content")) + fun content(): Optional = content.getOptional("content") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun functionCall(): Optional = - Optional.ofNullable(functionCall.getNullable("function_call")) + fun functionCall(): Optional = functionCall.getOptional("function_call") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun name(): Optional = name.getOptional("name") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ fun toolCalls(): Optional> = - Optional.ofNullable(toolCalls.getNullable("tool_calls")) + toolCalls.getOptional("tool_calls") /** * Returns the raw JSON value of [role]. @@ -2916,14 +2914,13 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun content(): Optional = Optional.ofNullable(content.getNullable("content")) + fun content(): Optional = content.getOptional("content") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun toolCallId(): Optional = - Optional.ofNullable(toolCallId.getNullable("tool_call_id")) + fun toolCallId(): Optional = toolCallId.getOptional("tool_call_id") /** * Returns the raw JSON value of [role]. @@ -3278,7 +3275,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun content(): Optional = Optional.ofNullable(content.getNullable("content")) + fun content(): Optional = content.getOptional("content") /** * Returns the raw JSON value of [name]. @@ -3621,7 +3618,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun content(): Optional = Optional.ofNullable(content.getNullable("content")) + fun content(): Optional = content.getOptional("content") /** * Returns the raw JSON value of [role]. @@ -4376,7 +4373,7 @@ private constructor( * if the server responded with an unexpected value). */ fun propagatedEvent(): Optional = - Optional.ofNullable(propagatedEvent.getNullable("propagated_event")) + propagatedEvent.getOptional("propagated_event") /** * Identifiers for the row to to log a subspan under @@ -4384,7 +4381,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun rowIds(): Optional = Optional.ofNullable(rowIds.getNullable("row_ids")) + fun rowIds(): Optional = rowIds.getOptional("row_ids") /** * Returns the raw JSON value of [objectId]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPage.kt index b412fcd4..46b65193 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPage.kt @@ -86,7 +86,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageAsync.kt index 8f2dd4e8..df33ddc9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageAsync.kt @@ -18,6 +18,7 @@ import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor import java.util.function.Predicate +import kotlin.jvm.optionals.getOrNull /** * List out all functions. The functions are sorted by creation date, with the most recently-created @@ -91,7 +92,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionReplaceParams.kt index 3e7da53f..79093cb3 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionReplaceParams.kt @@ -635,8 +635,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * JSON schema for the function's parameters and return type @@ -645,20 +644,19 @@ private constructor( * the server responded with an unexpected value). */ fun functionSchema(): Optional = - Optional.ofNullable(functionSchema.getNullable("function_schema")) + functionSchema.getOptional("function_schema") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun functionType(): Optional = - Optional.ofNullable(functionType.getNullable("function_type")) + fun functionType(): Optional = functionType.getOptional("function_type") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun origin(): Optional = Optional.ofNullable(origin.getNullable("origin")) + fun origin(): Optional = origin.getOptional("origin") /** * The prompt, model, and its parameters @@ -666,8 +664,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun promptData(): Optional = - Optional.ofNullable(promptData.getNullable("prompt_data")) + fun promptData(): Optional = promptData.getOptional("prompt_data") /** * A list of tags for the prompt @@ -675,7 +672,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) + fun tags(): Optional> = tags.getOptional("tags") /** * Returns the raw JSON value of [functionData]. @@ -2004,8 +2001,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type (e.g. if the server responded with an unexpected value). */ - fun preview(): Optional = - Optional.ofNullable(preview.getNullable("preview")) + fun preview(): Optional = preview.getOptional("preview") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected @@ -3927,7 +3923,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun internal_(): Optional = Optional.ofNullable(internal_.getNullable("internal")) + fun internal_(): Optional = internal_.getOptional("internal") /** * Returns the raw JSON value of [objectId]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt index 971bca89..bc199968 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt @@ -451,15 +451,13 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun functionData(): Optional = - Optional.ofNullable(functionData.getNullable("function_data")) + fun functionData(): Optional = functionData.getOptional("function_data") /** * Name of the prompt @@ -467,7 +465,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun name(): Optional = name.getOptional("name") /** * The prompt, model, and its parameters @@ -475,8 +473,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun promptData(): Optional = - Optional.ofNullable(promptData.getNullable("prompt_data")) + fun promptData(): Optional = promptData.getOptional("prompt_data") /** * A list of tags for the prompt @@ -484,7 +481,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) + fun tags(): Optional> = tags.getOptional("tags") /** * Returns the raw JSON value of [description]. @@ -1660,8 +1657,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type (e.g. if the server responded with an unexpected value). */ - fun preview(): Optional = - Optional.ofNullable(preview.getNullable("preview")) + fun preview(): Optional = preview.getOptional("preview") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Group.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Group.kt index f8ac8b97..756c44c0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Group.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Group.kt @@ -105,7 +105,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun created(): Optional = Optional.ofNullable(created.getNullable("created")) + fun created(): Optional = created.getOptional("created") /** * Date of group deletion, or null if the group is still active @@ -113,8 +113,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun deletedAt(): Optional = - Optional.ofNullable(deletedAt.getNullable("deleted_at")) + fun deletedAt(): Optional = deletedAt.getOptional("deleted_at") /** * Textual description of the group @@ -122,8 +121,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * Ids of the groups this group inherits from @@ -134,8 +132,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun memberGroups(): Optional> = - Optional.ofNullable(memberGroups.getNullable("member_groups")) + fun memberGroups(): Optional> = memberGroups.getOptional("member_groups") /** * Ids of users which belong to this group @@ -143,8 +140,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun memberUsers(): Optional> = - Optional.ofNullable(memberUsers.getNullable("member_users")) + fun memberUsers(): Optional> = memberUsers.getOptional("member_users") /** * Identifies the user who created the group @@ -152,7 +148,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) + fun userId(): Optional = userId.getOptional("user_id") /** * Returns the raw JSON value of [id]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupCreateParams.kt index 893d9218..8843a37b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupCreateParams.kt @@ -442,8 +442,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * Ids of the groups this group inherits from @@ -454,8 +453,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun memberGroups(): Optional> = - Optional.ofNullable(memberGroups.getNullable("member_groups")) + fun memberGroups(): Optional> = memberGroups.getOptional("member_groups") /** * Ids of users which belong to this group @@ -463,8 +461,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun memberUsers(): Optional> = - Optional.ofNullable(memberUsers.getNullable("member_users")) + fun memberUsers(): Optional> = memberUsers.getOptional("member_users") /** * For nearly all users, this parameter should be unnecessary. But in the rare case that @@ -474,7 +471,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) + fun orgName(): Optional = orgName.getOptional("org_name") /** * Returns the raw JSON value of [name]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt index 25297bb8..29cb7043 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt @@ -86,7 +86,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt index 4bc457e6..35febb40 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt @@ -18,6 +18,7 @@ import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor import java.util.function.Predicate +import kotlin.jvm.optionals.getOrNull /** * List out all groups. The groups are sorted by creation date, with the most recently-created @@ -88,7 +89,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupReplaceParams.kt index e53d938c..281249c7 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupReplaceParams.kt @@ -442,8 +442,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * Ids of the groups this group inherits from @@ -454,8 +453,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun memberGroups(): Optional> = - Optional.ofNullable(memberGroups.getNullable("member_groups")) + fun memberGroups(): Optional> = memberGroups.getOptional("member_groups") /** * Ids of users which belong to this group @@ -463,8 +461,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun memberUsers(): Optional> = - Optional.ofNullable(memberUsers.getNullable("member_users")) + fun memberUsers(): Optional> = memberUsers.getOptional("member_users") /** * For nearly all users, this parameter should be unnecessary. But in the rare case that @@ -474,7 +471,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) + fun orgName(): Optional = orgName.getOptional("org_name") /** * Returns the raw JSON value of [name]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupUpdateParams.kt index 93b812ad..1eef9986 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupUpdateParams.kt @@ -525,7 +525,7 @@ private constructor( * the server responded with an unexpected value). */ fun addMemberGroups(): Optional> = - Optional.ofNullable(addMemberGroups.getNullable("add_member_groups")) + addMemberGroups.getOptional("add_member_groups") /** * A list of user IDs to add to the group @@ -534,7 +534,7 @@ private constructor( * the server responded with an unexpected value). */ fun addMemberUsers(): Optional> = - Optional.ofNullable(addMemberUsers.getNullable("add_member_users")) + addMemberUsers.getOptional("add_member_users") /** * Textual description of the group @@ -542,8 +542,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * Name of the group @@ -551,7 +550,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun name(): Optional = name.getOptional("name") /** * A list of group IDs to remove from the group's inheriting-from set @@ -560,7 +559,7 @@ private constructor( * the server responded with an unexpected value). */ fun removeMemberGroups(): Optional> = - Optional.ofNullable(removeMemberGroups.getNullable("remove_member_groups")) + removeMemberGroups.getOptional("remove_member_groups") /** * A list of user IDs to remove from the group @@ -569,7 +568,7 @@ private constructor( * the server responded with an unexpected value). */ fun removeMemberUsers(): Optional> = - Optional.ofNullable(removeMemberUsers.getNullable("remove_member_users")) + removeMemberUsers.getOptional("remove_member_users") /** * Returns the raw JSON value of [addMemberGroups]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertDatasetEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertDatasetEvent.kt index d8135d03..f19ac1e2 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertDatasetEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertDatasetEvent.kt @@ -92,7 +92,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun id(): Optional = Optional.ofNullable(id.getNullable("id")) + fun id(): Optional = id.getOptional("id") /** * The `_is_merge` field controls how the row is merged with any existing row with the same id @@ -109,7 +109,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun _isMerge(): Optional = Optional.ofNullable(_isMerge.getNullable("_is_merge")) + fun _isMerge(): Optional = _isMerge.getOptional("_is_merge") /** * The `_merge_paths` field allows controlling the depth of the merge, when `_is_merge=true`. @@ -127,8 +127,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun _mergePaths(): Optional>> = - Optional.ofNullable(_mergePaths.getNullable("_merge_paths")) + fun _mergePaths(): Optional>> = _mergePaths.getOptional("_merge_paths") /** * Pass `_object_delete=true` to mark the dataset event deleted. Deleted events will not show up @@ -137,8 +136,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun _objectDelete(): Optional = - Optional.ofNullable(_objectDelete.getNullable("_object_delete")) + fun _objectDelete(): Optional = _objectDelete.getOptional("_object_delete") /** * DEPRECATED: The `_parent_id` field is deprecated and should not be used. Support for @@ -161,7 +159,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun _parentId(): Optional = Optional.ofNullable(_parentId.getNullable("_parent_id")) + fun _parentId(): Optional = _parentId.getOptional("_parent_id") /** * The timestamp the dataset event was created @@ -169,7 +167,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun created(): Optional = Optional.ofNullable(created.getNullable("created")) + fun created(): Optional = created.getOptional("created") /** * The output of your application, including post-processing (an arbitrary, JSON serializable @@ -190,7 +188,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun metadata(): Optional = metadata.getOptional("metadata") /** * Indicates the event was copied from another object. @@ -198,7 +196,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun origin(): Optional = Optional.ofNullable(origin.getNullable("origin")) + fun origin(): Optional = origin.getOptional("origin") /** * Use `span_id`, `root_span_id`, and `span_parents` instead of `_parent_id`, which is now @@ -219,7 +217,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun rootSpanId(): Optional = Optional.ofNullable(rootSpanId.getNullable("root_span_id")) + fun rootSpanId(): Optional = rootSpanId.getOptional("root_span_id") /** * Use `span_id`, `root_span_id`, and `span_parents` instead of `_parent_id`, which is now @@ -240,7 +238,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun spanId(): Optional = Optional.ofNullable(spanId.getNullable("span_id")) + fun spanId(): Optional = spanId.getOptional("span_id") /** * Use `span_id`, `root_span_id`, and `span_parents` instead of `_parent_id`, which is now @@ -261,8 +259,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun spanParents(): Optional> = - Optional.ofNullable(spanParents.getNullable("span_parents")) + fun spanParents(): Optional> = spanParents.getOptional("span_parents") /** * A list of tags to log @@ -270,7 +267,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) + fun tags(): Optional> = tags.getOptional("tags") /** * Returns the raw JSON value of [id]. @@ -884,7 +881,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun model(): Optional = Optional.ofNullable(model.getNullable("model")) + fun model(): Optional = model.getOptional("model") /** * Returns the raw JSON value of [model]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertExperimentEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertExperimentEvent.kt index 95532feb..d45b6b9a 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertExperimentEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertExperimentEvent.kt @@ -112,7 +112,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun id(): Optional = Optional.ofNullable(id.getNullable("id")) + fun id(): Optional = id.getOptional("id") /** * The `_is_merge` field controls how the row is merged with any existing row with the same id @@ -129,7 +129,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun _isMerge(): Optional = Optional.ofNullable(_isMerge.getNullable("_is_merge")) + fun _isMerge(): Optional = _isMerge.getOptional("_is_merge") /** * The `_merge_paths` field allows controlling the depth of the merge, when `_is_merge=true`. @@ -147,8 +147,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun _mergePaths(): Optional>> = - Optional.ofNullable(_mergePaths.getNullable("_merge_paths")) + fun _mergePaths(): Optional>> = _mergePaths.getOptional("_merge_paths") /** * Pass `_object_delete=true` to mark the experiment event deleted. Deleted events will not show @@ -157,8 +156,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun _objectDelete(): Optional = - Optional.ofNullable(_objectDelete.getNullable("_object_delete")) + fun _objectDelete(): Optional = _objectDelete.getOptional("_object_delete") /** * DEPRECATED: The `_parent_id` field is deprecated and should not be used. Support for @@ -181,7 +179,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun _parentId(): Optional = Optional.ofNullable(_parentId.getNullable("_parent_id")) + fun _parentId(): Optional = _parentId.getOptional("_parent_id") /** * Context is additional information about the code that produced the experiment event. It is @@ -191,7 +189,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun context(): Optional = Optional.ofNullable(context.getNullable("context")) + fun context(): Optional = context.getOptional("context") /** * The timestamp the experiment event was created @@ -199,7 +197,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun created(): Optional = Optional.ofNullable(created.getNullable("created")) + fun created(): Optional = created.getOptional("created") /** The error that occurred, if any. */ @JsonProperty("error") @ExcludeMissing fun _error(): JsonValue = error @@ -232,7 +230,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun metadata(): Optional = metadata.getOptional("metadata") /** * Metrics are numerical measurements tracking the execution of the code that produced the @@ -242,7 +240,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun metrics(): Optional = Optional.ofNullable(metrics.getNullable("metrics")) + fun metrics(): Optional = metrics.getOptional("metrics") /** * Indicates the event was copied from another object. @@ -250,7 +248,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun origin(): Optional = Optional.ofNullable(origin.getNullable("origin")) + fun origin(): Optional = origin.getOptional("origin") /** * The output of your application, including post-processing (an arbitrary, JSON serializable @@ -280,7 +278,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun rootSpanId(): Optional = Optional.ofNullable(rootSpanId.getNullable("root_span_id")) + fun rootSpanId(): Optional = rootSpanId.getOptional("root_span_id") /** * A dictionary of numeric values (between 0 and 1) to log. The scores should give you a variety @@ -294,7 +292,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun scores(): Optional = Optional.ofNullable(scores.getNullable("scores")) + fun scores(): Optional = scores.getOptional("scores") /** * Human-identifying attributes of the span, such as name, type, etc. @@ -302,8 +300,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun spanAttributes(): Optional = - Optional.ofNullable(spanAttributes.getNullable("span_attributes")) + fun spanAttributes(): Optional = spanAttributes.getOptional("span_attributes") /** * Use `span_id`, `root_span_id`, and `span_parents` instead of `_parent_id`, which is now @@ -324,7 +321,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun spanId(): Optional = Optional.ofNullable(spanId.getNullable("span_id")) + fun spanId(): Optional = spanId.getOptional("span_id") /** * Use `span_id`, `root_span_id`, and `span_parents` instead of `_parent_id`, which is now @@ -345,8 +342,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun spanParents(): Optional> = - Optional.ofNullable(spanParents.getNullable("span_parents")) + fun spanParents(): Optional> = spanParents.getOptional("span_parents") /** * A list of tags to log @@ -354,7 +350,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) + fun tags(): Optional> = tags.getOptional("tags") /** * Returns the raw JSON value of [id]. @@ -1128,8 +1124,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun callerFilename(): Optional = - Optional.ofNullable(callerFilename.getNullable("caller_filename")) + fun callerFilename(): Optional = callerFilename.getOptional("caller_filename") /** * The function in code which created the experiment event @@ -1138,7 +1133,7 @@ private constructor( * the server responded with an unexpected value). */ fun callerFunctionname(): Optional = - Optional.ofNullable(callerFunctionname.getNullable("caller_functionname")) + callerFunctionname.getOptional("caller_functionname") /** * Line of code where the experiment event was created @@ -1146,8 +1141,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun callerLineno(): Optional = - Optional.ofNullable(callerLineno.getNullable("caller_lineno")) + fun callerLineno(): Optional = callerLineno.getOptional("caller_lineno") /** * Returns the raw JSON value of [callerFilename]. @@ -1386,7 +1380,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun model(): Optional = Optional.ofNullable(model.getNullable("model")) + fun model(): Optional = model.getOptional("model") /** * Returns the raw JSON value of [model]. @@ -1582,8 +1576,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun completionTokens(): Optional = - Optional.ofNullable(completionTokens.getNullable("completion_tokens")) + fun completionTokens(): Optional = completionTokens.getOptional("completion_tokens") /** * A unix timestamp recording when the section of code which produced the experiment event @@ -1592,7 +1585,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun end(): Optional = Optional.ofNullable(end.getNullable("end")) + fun end(): Optional = end.getOptional("end") /** * The number of tokens in the prompt used to generate the experiment event (only set if @@ -1601,8 +1594,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun promptTokens(): Optional = - Optional.ofNullable(promptTokens.getNullable("prompt_tokens")) + fun promptTokens(): Optional = promptTokens.getOptional("prompt_tokens") /** * A unix timestamp recording when the section of code which produced the experiment event @@ -1611,7 +1603,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun start(): Optional = Optional.ofNullable(start.getNullable("start")) + fun start(): Optional = start.getOptional("start") /** * The total number of tokens in the input and output of the experiment event. @@ -1619,7 +1611,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun tokens(): Optional = Optional.ofNullable(tokens.getNullable("tokens")) + fun tokens(): Optional = tokens.getOptional("tokens") /** * Returns the raw JSON value of [completionTokens]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertProjectLogsEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertProjectLogsEvent.kt index e8b56179..1062598d 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertProjectLogsEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertProjectLogsEvent.kt @@ -112,7 +112,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun id(): Optional = Optional.ofNullable(id.getNullable("id")) + fun id(): Optional = id.getOptional("id") /** * The `_is_merge` field controls how the row is merged with any existing row with the same id @@ -129,7 +129,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun _isMerge(): Optional = Optional.ofNullable(_isMerge.getNullable("_is_merge")) + fun _isMerge(): Optional = _isMerge.getOptional("_is_merge") /** * The `_merge_paths` field allows controlling the depth of the merge, when `_is_merge=true`. @@ -147,8 +147,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun _mergePaths(): Optional>> = - Optional.ofNullable(_mergePaths.getNullable("_merge_paths")) + fun _mergePaths(): Optional>> = _mergePaths.getOptional("_merge_paths") /** * Pass `_object_delete=true` to mark the project logs event deleted. Deleted events will not @@ -157,8 +156,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun _objectDelete(): Optional = - Optional.ofNullable(_objectDelete.getNullable("_object_delete")) + fun _objectDelete(): Optional = _objectDelete.getOptional("_object_delete") /** * DEPRECATED: The `_parent_id` field is deprecated and should not be used. Support for @@ -181,7 +179,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun _parentId(): Optional = Optional.ofNullable(_parentId.getNullable("_parent_id")) + fun _parentId(): Optional = _parentId.getOptional("_parent_id") /** * Context is additional information about the code that produced the project logs event. It is @@ -191,7 +189,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun context(): Optional = Optional.ofNullable(context.getNullable("context")) + fun context(): Optional = context.getOptional("context") /** * The timestamp the project logs event was created @@ -199,7 +197,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun created(): Optional = Optional.ofNullable(created.getNullable("created")) + fun created(): Optional = created.getOptional("created") /** The error that occurred, if any. */ @JsonProperty("error") @ExcludeMissing fun _error(): JsonValue = error @@ -227,7 +225,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun metadata(): Optional = metadata.getOptional("metadata") /** * Metrics are numerical measurements tracking the execution of the code that produced the @@ -237,7 +235,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun metrics(): Optional = Optional.ofNullable(metrics.getNullable("metrics")) + fun metrics(): Optional = metrics.getOptional("metrics") /** * Indicates the event was copied from another object. @@ -245,7 +243,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun origin(): Optional = Optional.ofNullable(origin.getNullable("origin")) + fun origin(): Optional = origin.getOptional("origin") /** * The output of your application, including post-processing (an arbitrary, JSON serializable @@ -275,7 +273,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun rootSpanId(): Optional = Optional.ofNullable(rootSpanId.getNullable("root_span_id")) + fun rootSpanId(): Optional = rootSpanId.getOptional("root_span_id") /** * A dictionary of numeric values (between 0 and 1) to log. The scores should give you a variety @@ -289,7 +287,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun scores(): Optional = Optional.ofNullable(scores.getNullable("scores")) + fun scores(): Optional = scores.getOptional("scores") /** * Human-identifying attributes of the span, such as name, type, etc. @@ -297,8 +295,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun spanAttributes(): Optional = - Optional.ofNullable(spanAttributes.getNullable("span_attributes")) + fun spanAttributes(): Optional = spanAttributes.getOptional("span_attributes") /** * Use `span_id`, `root_span_id`, and `span_parents` instead of `_parent_id`, which is now @@ -319,7 +316,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun spanId(): Optional = Optional.ofNullable(spanId.getNullable("span_id")) + fun spanId(): Optional = spanId.getOptional("span_id") /** * Use `span_id`, `root_span_id`, and `span_parents` instead of `_parent_id`, which is now @@ -340,8 +337,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun spanParents(): Optional> = - Optional.ofNullable(spanParents.getNullable("span_parents")) + fun spanParents(): Optional> = spanParents.getOptional("span_parents") /** * A list of tags to log @@ -349,7 +345,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) + fun tags(): Optional> = tags.getOptional("tags") /** * Returns the raw JSON value of [id]. @@ -1120,8 +1116,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun callerFilename(): Optional = - Optional.ofNullable(callerFilename.getNullable("caller_filename")) + fun callerFilename(): Optional = callerFilename.getOptional("caller_filename") /** * The function in code which created the project logs event @@ -1130,7 +1125,7 @@ private constructor( * the server responded with an unexpected value). */ fun callerFunctionname(): Optional = - Optional.ofNullable(callerFunctionname.getNullable("caller_functionname")) + callerFunctionname.getOptional("caller_functionname") /** * Line of code where the project logs event was created @@ -1138,8 +1133,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun callerLineno(): Optional = - Optional.ofNullable(callerLineno.getNullable("caller_lineno")) + fun callerLineno(): Optional = callerLineno.getOptional("caller_lineno") /** * Returns the raw JSON value of [callerFilename]. @@ -1378,7 +1372,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun model(): Optional = Optional.ofNullable(model.getNullable("model")) + fun model(): Optional = model.getOptional("model") /** * Returns the raw JSON value of [model]. @@ -1574,8 +1568,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun completionTokens(): Optional = - Optional.ofNullable(completionTokens.getNullable("completion_tokens")) + fun completionTokens(): Optional = completionTokens.getOptional("completion_tokens") /** * A unix timestamp recording when the section of code which produced the project logs event @@ -1584,7 +1577,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun end(): Optional = Optional.ofNullable(end.getNullable("end")) + fun end(): Optional = end.getOptional("end") /** * The number of tokens in the prompt used to generate the project logs event (only set if @@ -1593,8 +1586,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun promptTokens(): Optional = - Optional.ofNullable(promptTokens.getNullable("prompt_tokens")) + fun promptTokens(): Optional = promptTokens.getOptional("prompt_tokens") /** * A unix timestamp recording when the section of code which produced the project logs event @@ -1603,7 +1595,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun start(): Optional = Optional.ofNullable(start.getNullable("start")) + fun start(): Optional = start.getOptional("start") /** * The total number of tokens in the input and output of the project logs event. @@ -1611,7 +1603,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun tokens(): Optional = Optional.ofNullable(tokens.getNullable("tokens")) + fun tokens(): Optional = tokens.getOptional("tokens") /** * Returns the raw JSON value of [completionTokens]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/MetricSummary.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/MetricSummary.kt index 2eb6fef9..04a8b3fe 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/MetricSummary.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/MetricSummary.kt @@ -88,7 +88,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun diff(): Optional = Optional.ofNullable(diff.getNullable("diff")) + fun diff(): Optional = diff.getOptional("diff") /** * Returns the raw JSON value of [improvements]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ObjectReference.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ObjectReference.kt index 454b2d28..b55336ff 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ObjectReference.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ObjectReference.kt @@ -78,7 +78,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun created(): Optional = Optional.ofNullable(created.getNullable("created")) + fun created(): Optional = created.getOptional("created") /** * Returns the raw JSON value of [id]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OnlineScoreConfig.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OnlineScoreConfig.kt index 58e76cae..e44af8fe 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OnlineScoreConfig.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OnlineScoreConfig.kt @@ -78,8 +78,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun applyToRootSpan(): Optional = - Optional.ofNullable(applyToRootSpan.getNullable("apply_to_root_span")) + fun applyToRootSpan(): Optional = applyToRootSpan.getOptional("apply_to_root_span") /** * Trigger online scoring on any spans with a name in this list @@ -88,7 +87,7 @@ private constructor( * server responded with an unexpected value). */ fun applyToSpanNames(): Optional> = - Optional.ofNullable(applyToSpanNames.getNullable("apply_to_span_names")) + applyToSpanNames.getOptional("apply_to_span_names") /** * Returns the raw JSON value of [samplingRate]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Organization.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Organization.kt index 63cfbf92..d80fcb7f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Organization.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Organization.kt @@ -67,7 +67,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun apiUrl(): Optional = Optional.ofNullable(apiUrl.getNullable("api_url")) + fun apiUrl(): Optional = apiUrl.getOptional("api_url") /** * Date of organization creation @@ -75,27 +75,25 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun created(): Optional = Optional.ofNullable(created.getNullable("created")) + fun created(): Optional = created.getOptional("created") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun isUniversalApi(): Optional = - Optional.ofNullable(isUniversalApi.getNullable("is_universal_api")) + fun isUniversalApi(): Optional = isUniversalApi.getOptional("is_universal_api") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun proxyUrl(): Optional = Optional.ofNullable(proxyUrl.getNullable("proxy_url")) + fun proxyUrl(): Optional = proxyUrl.getOptional("proxy_url") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun realtimeUrl(): Optional = - Optional.ofNullable(realtimeUrl.getNullable("realtime_url")) + fun realtimeUrl(): Optional = realtimeUrl.getOptional("realtime_url") /** * Returns the raw JSON value of [id]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt index 91510104..8bd16fed 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt @@ -89,7 +89,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt index c17537ef..59689415 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt @@ -18,6 +18,7 @@ import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor import java.util.function.Predicate +import kotlin.jvm.optionals.getOrNull /** * List out all organizations. The organizations are sorted by creation date, with the most @@ -91,7 +92,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationMemberUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationMemberUpdateParams.kt index 461b106f..0cb08253 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationMemberUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationMemberUpdateParams.kt @@ -371,8 +371,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun inviteUsers(): Optional = - Optional.ofNullable(inviteUsers.getNullable("invite_users")) + fun inviteUsers(): Optional = inviteUsers.getOptional("invite_users") /** * For nearly all users, this parameter should be unnecessary. But in the rare case that @@ -382,7 +381,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun orgId(): Optional = Optional.ofNullable(orgId.getNullable("org_id")) + fun orgId(): Optional = orgId.getOptional("org_id") /** * For nearly all users, this parameter should be unnecessary. But in the rare case that @@ -392,7 +391,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) + fun orgName(): Optional = orgName.getOptional("org_name") /** * Users to remove from the organization @@ -400,8 +399,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun removeUsers(): Optional = - Optional.ofNullable(removeUsers.getNullable("remove_users")) + fun removeUsers(): Optional = removeUsers.getOptional("remove_users") /** * Returns the raw JSON value of [inviteUsers]. @@ -679,7 +677,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun emails(): Optional> = Optional.ofNullable(emails.getNullable("emails")) + fun emails(): Optional> = emails.getOptional("emails") /** * Singular form of group_ids @@ -687,7 +685,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun groupId(): Optional = Optional.ofNullable(groupId.getNullable("group_id")) + fun groupId(): Optional = groupId.getOptional("group_id") /** * Optional list of group ids to add newly-invited users to. @@ -695,8 +693,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun groupIds(): Optional> = - Optional.ofNullable(groupIds.getNullable("group_ids")) + fun groupIds(): Optional> = groupIds.getOptional("group_ids") /** * Singular form of group_names @@ -704,7 +701,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun groupName(): Optional = Optional.ofNullable(groupName.getNullable("group_name")) + fun groupName(): Optional = groupName.getOptional("group_name") /** * Optional list of group names to add newly-invited users to. @@ -712,8 +709,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun groupNames(): Optional> = - Optional.ofNullable(groupNames.getNullable("group_names")) + fun groupNames(): Optional> = groupNames.getOptional("group_names") /** * Ids of existing users to invite @@ -721,7 +717,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun ids(): Optional> = Optional.ofNullable(ids.getNullable("ids")) + fun ids(): Optional> = ids.getOptional("ids") /** * If true, send invite emails to the users who wore actually added @@ -730,7 +726,7 @@ private constructor( * the server responded with an unexpected value). */ fun sendInviteEmails(): Optional = - Optional.ofNullable(sendInviteEmails.getNullable("send_invite_emails")) + sendInviteEmails.getOptional("send_invite_emails") /** * Returns the raw JSON value of [emails]. @@ -1120,7 +1116,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun emails(): Optional> = Optional.ofNullable(emails.getNullable("emails")) + fun emails(): Optional> = emails.getOptional("emails") /** * Ids of users to remove @@ -1128,7 +1124,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun ids(): Optional> = Optional.ofNullable(ids.getNullable("ids")) + fun ids(): Optional> = ids.getOptional("ids") /** * Returns the raw JSON value of [emails]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationUpdateParams.kt index f34af0f5..83ffe1a5 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationUpdateParams.kt @@ -414,14 +414,13 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun apiUrl(): Optional = Optional.ofNullable(apiUrl.getNullable("api_url")) + fun apiUrl(): Optional = apiUrl.getOptional("api_url") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun isUniversalApi(): Optional = - Optional.ofNullable(isUniversalApi.getNullable("is_universal_api")) + fun isUniversalApi(): Optional = isUniversalApi.getOptional("is_universal_api") /** * Name of the organization @@ -429,20 +428,19 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun name(): Optional = name.getOptional("name") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun proxyUrl(): Optional = Optional.ofNullable(proxyUrl.getNullable("proxy_url")) + fun proxyUrl(): Optional = proxyUrl.getOptional("proxy_url") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun realtimeUrl(): Optional = - Optional.ofNullable(realtimeUrl.getNullable("realtime_url")) + fun realtimeUrl(): Optional = realtimeUrl.getOptional("realtime_url") /** * Returns the raw JSON value of [apiUrl]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PatchOrganizationMembersOutput.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PatchOrganizationMembersOutput.kt index b767f148..03a43cc2 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PatchOrganizationMembersOutput.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PatchOrganizationMembersOutput.kt @@ -56,8 +56,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun sendEmailError(): Optional = - Optional.ofNullable(sendEmailError.getNullable("send_email_error")) + fun sendEmailError(): Optional = sendEmailError.getOptional("send_email_error") /** * Returns the raw JSON value of [orgId]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Project.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Project.kt index ee53dccb..44902bf4 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Project.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Project.kt @@ -77,7 +77,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun created(): Optional = Optional.ofNullable(created.getNullable("created")) + fun created(): Optional = created.getOptional("created") /** * Date of project deletion, or null if the project is still active @@ -85,15 +85,13 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun deletedAt(): Optional = - Optional.ofNullable(deletedAt.getNullable("deleted_at")) + fun deletedAt(): Optional = deletedAt.getOptional("deleted_at") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun settings(): Optional = - Optional.ofNullable(settings.getNullable("settings")) + fun settings(): Optional = settings.getOptional("settings") /** * Identifies the user who created the project @@ -101,7 +99,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) + fun userId(): Optional = userId.getOptional("user_id") /** * Returns the raw JSON value of [id]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectCreateParams.kt index cbd85fab..f09b95b2 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectCreateParams.kt @@ -309,7 +309,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) + fun orgName(): Optional = orgName.getOptional("org_name") /** * Returns the raw JSON value of [name]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPage.kt index ca864b79..242b2908 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPage.kt @@ -86,7 +86,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageAsync.kt index 9ec07cbb..803d890c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageAsync.kt @@ -18,6 +18,7 @@ import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor import java.util.function.Predicate +import kotlin.jvm.optionals.getOrNull /** * List out all projects. The projects are sorted by creation date, with the most recently-created @@ -91,7 +92,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParams.kt index 40f597d0..31b5a074 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParams.kt @@ -512,7 +512,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun cursor(): Optional = Optional.ofNullable(cursor.getNullable("cursor")) + fun cursor(): Optional = cursor.getOptional("cursor") /** * limit the number of traces fetched @@ -532,7 +532,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun limit(): Optional = Optional.ofNullable(limit.getNullable("limit")) + fun limit(): Optional = limit.getOptional("limit") /** * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor of @@ -549,8 +549,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun maxRootSpanId(): Optional = - Optional.ofNullable(maxRootSpanId.getNullable("max_root_span_id")) + fun maxRootSpanId(): Optional = maxRootSpanId.getOptional("max_root_span_id") /** * DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor of @@ -567,8 +566,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun maxXactId(): Optional = - Optional.ofNullable(maxXactId.getNullable("max_xact_id")) + fun maxXactId(): Optional = maxXactId.getOptional("max_xact_id") /** * Retrieve a snapshot of events from a past time @@ -579,7 +577,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun version(): Optional = Optional.ofNullable(version.getNullable("version")) + fun version(): Optional = version.getOptional("version") /** * Returns the raw JSON value of [cursor]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogsEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogsEvent.kt index 59c8be8e..5d6dd53e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogsEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogsEvent.kt @@ -182,7 +182,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun context(): Optional = Optional.ofNullable(context.getNullable("context")) + fun context(): Optional = context.getOptional("context") /** The error that occurred, if any. */ @JsonProperty("error") @ExcludeMissing fun _error(): JsonValue = error @@ -206,7 +206,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun isRoot(): Optional = Optional.ofNullable(isRoot.getNullable("is_root")) + fun isRoot(): Optional = isRoot.getOptional("is_root") /** * A dictionary with additional data about the test example, model outputs, or just about @@ -218,7 +218,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun metadata(): Optional = metadata.getOptional("metadata") /** * Metrics are numerical measurements tracking the execution of the code that produced the @@ -228,7 +228,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun metrics(): Optional = Optional.ofNullable(metrics.getNullable("metrics")) + fun metrics(): Optional = metrics.getOptional("metrics") /** * Indicates the event was copied from another object. @@ -236,7 +236,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun origin(): Optional = Optional.ofNullable(origin.getNullable("origin")) + fun origin(): Optional = origin.getOptional("origin") /** * The output of your application, including post-processing (an arbitrary, JSON serializable @@ -259,7 +259,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun scores(): Optional = Optional.ofNullable(scores.getNullable("scores")) + fun scores(): Optional = scores.getOptional("scores") /** * Human-identifying attributes of the span, such as name, type, etc. @@ -267,8 +267,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun spanAttributes(): Optional = - Optional.ofNullable(spanAttributes.getNullable("span_attributes")) + fun spanAttributes(): Optional = spanAttributes.getOptional("span_attributes") /** * An array of the parent `span_ids` of this project logs event. This should be empty for the @@ -277,8 +276,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun spanParents(): Optional> = - Optional.ofNullable(spanParents.getNullable("span_parents")) + fun spanParents(): Optional> = spanParents.getOptional("span_parents") /** * A list of tags to log @@ -286,7 +284,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) + fun tags(): Optional> = tags.getOptional("tags") /** * Returns the raw JSON value of [id]. @@ -1096,8 +1094,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun callerFilename(): Optional = - Optional.ofNullable(callerFilename.getNullable("caller_filename")) + fun callerFilename(): Optional = callerFilename.getOptional("caller_filename") /** * The function in code which created the project logs event @@ -1106,7 +1103,7 @@ private constructor( * the server responded with an unexpected value). */ fun callerFunctionname(): Optional = - Optional.ofNullable(callerFunctionname.getNullable("caller_functionname")) + callerFunctionname.getOptional("caller_functionname") /** * Line of code where the project logs event was created @@ -1114,8 +1111,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun callerLineno(): Optional = - Optional.ofNullable(callerLineno.getNullable("caller_lineno")) + fun callerLineno(): Optional = callerLineno.getOptional("caller_lineno") /** * Returns the raw JSON value of [callerFilename]. @@ -1354,7 +1350,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun model(): Optional = Optional.ofNullable(model.getNullable("model")) + fun model(): Optional = model.getOptional("model") /** * Returns the raw JSON value of [model]. @@ -1550,8 +1546,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun completionTokens(): Optional = - Optional.ofNullable(completionTokens.getNullable("completion_tokens")) + fun completionTokens(): Optional = completionTokens.getOptional("completion_tokens") /** * A unix timestamp recording when the section of code which produced the project logs event @@ -1560,7 +1555,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun end(): Optional = Optional.ofNullable(end.getNullable("end")) + fun end(): Optional = end.getOptional("end") /** * The number of tokens in the prompt used to generate the project logs event (only set if @@ -1569,8 +1564,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun promptTokens(): Optional = - Optional.ofNullable(promptTokens.getNullable("prompt_tokens")) + fun promptTokens(): Optional = promptTokens.getOptional("prompt_tokens") /** * A unix timestamp recording when the section of code which produced the project logs event @@ -1579,7 +1573,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun start(): Optional = Optional.ofNullable(start.getNullable("start")) + fun start(): Optional = start.getOptional("start") /** * The total number of tokens in the input and output of the project logs event. @@ -1587,7 +1581,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun tokens(): Optional = Optional.ofNullable(tokens.getNullable("tokens")) + fun tokens(): Optional = tokens.getOptional("tokens") /** * Returns the raw JSON value of [completionTokens]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScore.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScore.kt index 36f2a4fc..48b771b0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScore.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScore.kt @@ -126,14 +126,13 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun categories(): Optional = - Optional.ofNullable(categories.getNullable("categories")) + fun categories(): Optional = categories.getOptional("categories") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun config(): Optional = Optional.ofNullable(config.getNullable("config")) + fun config(): Optional = config.getOptional("config") /** * Date of project score creation @@ -141,7 +140,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun created(): Optional = Optional.ofNullable(created.getNullable("created")) + fun created(): Optional = created.getOptional("created") /** * Textual description of the project score @@ -149,8 +148,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * An optional LexoRank-based string that sets the sort position for the score in the UI @@ -158,7 +156,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun position(): Optional = Optional.ofNullable(position.getNullable("position")) + fun position(): Optional = position.getOptional("position") /** * Returns the raw JSON value of [id]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreConfig.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreConfig.kt index 79716066..6e3e4571 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreConfig.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreConfig.kt @@ -41,21 +41,19 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun destination(): Optional = - Optional.ofNullable(destination.getNullable("destination")) + fun destination(): Optional = destination.getOptional("destination") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun multiSelect(): Optional = - Optional.ofNullable(multiSelect.getNullable("multi_select")) + fun multiSelect(): Optional = multiSelect.getOptional("multi_select") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun online(): Optional = Optional.ofNullable(online.getNullable("online")) + fun online(): Optional = online.getOptional("online") /** * Returns the raw JSON value of [destination]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParams.kt index 3ddc8813..ca9cd18b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParams.kt @@ -479,15 +479,13 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun categories(): Optional = - Optional.ofNullable(categories.getNullable("categories")) + fun categories(): Optional = categories.getOptional("categories") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun config(): Optional = - Optional.ofNullable(config.getNullable("config")) + fun config(): Optional = config.getOptional("config") /** * Textual description of the project score @@ -495,8 +493,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * Returns the raw JSON value of [name]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt index 73ffa350..9ca7e11c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt @@ -89,7 +89,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt index 62dc8535..c6112ce9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt @@ -18,6 +18,7 @@ import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor import java.util.function.Predicate +import kotlin.jvm.optionals.getOrNull /** * List out all project_scores. The project_scores are sorted by creation date, with the most @@ -91,7 +92,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParams.kt index 3ef235b4..4f9186a0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParams.kt @@ -480,15 +480,13 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun categories(): Optional = - Optional.ofNullable(categories.getNullable("categories")) + fun categories(): Optional = categories.getOptional("categories") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun config(): Optional = - Optional.ofNullable(config.getNullable("config")) + fun config(): Optional = config.getOptional("config") /** * Textual description of the project score @@ -496,8 +494,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * Returns the raw JSON value of [name]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt index 800a0e3b..3e601691 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt @@ -443,15 +443,13 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun categories(): Optional = - Optional.ofNullable(categories.getNullable("categories")) + fun categories(): Optional = categories.getOptional("categories") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun config(): Optional = - Optional.ofNullable(config.getNullable("config")) + fun config(): Optional = config.getOptional("config") /** * Textual description of the project score @@ -459,8 +457,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * Name of the project score @@ -468,7 +465,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun name(): Optional = name.getOptional("name") /** * The type of the configured score @@ -476,8 +473,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun scoreType(): Optional = - Optional.ofNullable(scoreType.getNullable("score_type")) + fun scoreType(): Optional = scoreType.getOptional("score_type") /** * Returns the raw JSON value of [categories]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectSettings.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectSettings.kt index 55e71559..474d6826 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectSettings.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectSettings.kt @@ -48,7 +48,7 @@ private constructor( * server responded with an unexpected value). */ fun baselineExperimentId(): Optional = - Optional.ofNullable(baselineExperimentId.getNullable("baseline_experiment_id")) + baselineExperimentId.getOptional("baseline_experiment_id") /** * The key used to join two experiments (defaults to `input`) @@ -56,8 +56,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun comparisonKey(): Optional = - Optional.ofNullable(comparisonKey.getNullable("comparison_key")) + fun comparisonKey(): Optional = comparisonKey.getOptional("comparison_key") /** * The order of the fields to display in the trace view @@ -66,7 +65,7 @@ private constructor( * server responded with an unexpected value). */ fun spanFieldOrder(): Optional> = - Optional.ofNullable(spanFieldOrder.getNullable("spanFieldOrder")) + spanFieldOrder.getOptional("spanFieldOrder") /** * Returns the raw JSON value of [baselineExperimentId]. @@ -312,7 +311,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun layout(): Optional = Optional.ofNullable(layout.getNullable("layout")) + fun layout(): Optional = layout.getOptional("layout") /** * Returns the raw JSON value of [columnId]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTag.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTag.kt index 69cc9f76..b97d8d90 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTag.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTag.kt @@ -85,7 +85,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun color(): Optional = Optional.ofNullable(color.getNullable("color")) + fun color(): Optional = color.getOptional("color") /** * Date of project tag creation @@ -93,7 +93,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun created(): Optional = Optional.ofNullable(created.getNullable("created")) + fun created(): Optional = created.getOptional("created") /** * Textual description of the project tag @@ -101,8 +101,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * Returns the raw JSON value of [id]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagCreateParams.kt index 8239d87c..c6346741 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagCreateParams.kt @@ -378,7 +378,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun color(): Optional = Optional.ofNullable(color.getNullable("color")) + fun color(): Optional = color.getOptional("color") /** * Textual description of the project tag @@ -386,8 +386,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * Returns the raw JSON value of [name]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt index a083440b..3c17b1d3 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt @@ -89,7 +89,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt index 5612baff..7b33b899 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt @@ -18,6 +18,7 @@ import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor import java.util.function.Predicate +import kotlin.jvm.optionals.getOrNull /** * List out all project_tags. The project_tags are sorted by creation date, with the most @@ -91,7 +92,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagReplaceParams.kt index 8d586be3..3b1cb3fd 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagReplaceParams.kt @@ -379,7 +379,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun color(): Optional = Optional.ofNullable(color.getNullable("color")) + fun color(): Optional = color.getOptional("color") /** * Textual description of the project tag @@ -387,8 +387,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * Returns the raw JSON value of [name]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParams.kt index 31736f8c..9f4bcf04 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParams.kt @@ -348,7 +348,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun color(): Optional = Optional.ofNullable(color.getNullable("color")) + fun color(): Optional = color.getOptional("color") /** * Textual description of the project tag @@ -356,8 +356,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * Name of the project tag @@ -365,7 +364,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun name(): Optional = name.getOptional("name") /** * Returns the raw JSON value of [color]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectUpdateParams.kt index 2874460a..b97b8926 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectUpdateParams.kt @@ -320,7 +320,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun name(): Optional = name.getOptional("name") /** * Project settings. Patch operations replace all settings, so make sure you include all @@ -329,8 +329,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun settings(): Optional = - Optional.ofNullable(settings.getNullable("settings")) + fun settings(): Optional = settings.getOptional("settings") /** * Returns the raw JSON value of [name]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Prompt.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Prompt.kt index 0b817608..9157056c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Prompt.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Prompt.kt @@ -143,7 +143,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun created(): Optional = Optional.ofNullable(created.getNullable("created")) + fun created(): Optional = created.getOptional("created") /** * Textual description of the prompt @@ -151,15 +151,13 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun functionType(): Optional = - Optional.ofNullable(functionType.getNullable("function_type")) + fun functionType(): Optional = functionType.getOptional("function_type") /** * User-controlled metadata about the prompt @@ -167,7 +165,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata")) + fun metadata(): Optional = metadata.getOptional("metadata") /** * The prompt, model, and its parameters @@ -175,8 +173,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun promptData(): Optional = - Optional.ofNullable(promptData.getNullable("prompt_data")) + fun promptData(): Optional = promptData.getOptional("prompt_data") /** * A list of tags for the prompt @@ -184,7 +181,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) + fun tags(): Optional> = tags.getOptional("tags") /** * Returns the raw JSON value of [id]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptCreateParams.kt index 79da4321..b631e3b1 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptCreateParams.kt @@ -497,15 +497,13 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun functionType(): Optional = - Optional.ofNullable(functionType.getNullable("function_type")) + fun functionType(): Optional = functionType.getOptional("function_type") /** * The prompt, model, and its parameters @@ -513,8 +511,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun promptData(): Optional = - Optional.ofNullable(promptData.getNullable("prompt_data")) + fun promptData(): Optional = promptData.getOptional("prompt_data") /** * A list of tags for the prompt @@ -522,7 +519,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) + fun tags(): Optional> = tags.getOptional("tags") /** * Returns the raw JSON value of [name]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptData.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptData.kt index 5decef33..9248eaac 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptData.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptData.kt @@ -59,32 +59,31 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun options(): Optional = Optional.ofNullable(options.getNullable("options")) + fun options(): Optional = options.getOptional("options") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun origin(): Optional = Optional.ofNullable(origin.getNullable("origin")) + fun origin(): Optional = origin.getOptional("origin") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun parser(): Optional = Optional.ofNullable(parser.getNullable("parser")) + fun parser(): Optional = parser.getOptional("parser") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun prompt(): Optional = Optional.ofNullable(prompt.getNullable("prompt")) + fun prompt(): Optional = prompt.getOptional("prompt") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun toolFunctions(): Optional> = - Optional.ofNullable(toolFunctions.getNullable("tool_functions")) + fun toolFunctions(): Optional> = toolFunctions.getOptional("tool_functions") /** * Returns the raw JSON value of [options]. @@ -354,20 +353,19 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun projectId(): Optional = Optional.ofNullable(projectId.getNullable("project_id")) + fun projectId(): Optional = projectId.getOptional("project_id") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun promptId(): Optional = Optional.ofNullable(promptId.getNullable("prompt_id")) + fun promptId(): Optional = promptId.getOptional("prompt_id") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun promptVersion(): Optional = - Optional.ofNullable(promptVersion.getNullable("prompt_version")) + fun promptVersion(): Optional = promptVersion.getOptional("prompt_version") /** * Returns the raw JSON value of [projectId]. @@ -1522,7 +1520,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun tools(): Optional = Optional.ofNullable(tools.getNullable("tools")) + fun tools(): Optional = tools.getOptional("tools") /** * Returns the raw JSON value of [messages]. @@ -2034,14 +2032,13 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type (e.g. if the server responded with an unexpected value). */ - fun content(): Optional = - Optional.ofNullable(content.getNullable("content")) + fun content(): Optional = content.getOptional("content") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type (e.g. if the server responded with an unexpected value). */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun name(): Optional = name.getOptional("name") /** * Returns the raw JSON value of [role]. @@ -2399,14 +2396,13 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type (e.g. if the server responded with an unexpected value). */ - fun content(): Optional = - Optional.ofNullable(content.getNullable("content")) + fun content(): Optional = content.getOptional("content") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type (e.g. if the server responded with an unexpected value). */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun name(): Optional = name.getOptional("name") /** * Returns the raw JSON value of [role]. @@ -3194,28 +3190,27 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type (e.g. if the server responded with an unexpected value). */ - fun content(): Optional = - Optional.ofNullable(content.getNullable("content")) + fun content(): Optional = content.getOptional("content") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type (e.g. if the server responded with an unexpected value). */ fun functionCall(): Optional = - Optional.ofNullable(functionCall.getNullable("function_call")) + functionCall.getOptional("function_call") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type (e.g. if the server responded with an unexpected value). */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun name(): Optional = name.getOptional("name") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type (e.g. if the server responded with an unexpected value). */ fun toolCalls(): Optional> = - Optional.ofNullable(toolCalls.getNullable("tool_calls")) + toolCalls.getOptional("tool_calls") /** * Returns the raw JSON value of [role]. @@ -3874,15 +3869,13 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type (e.g. if the server responded with an unexpected value). */ - fun content(): Optional = - Optional.ofNullable(content.getNullable("content")) + fun content(): Optional = content.getOptional("content") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type (e.g. if the server responded with an unexpected value). */ - fun toolCallId(): Optional = - Optional.ofNullable(toolCallId.getNullable("tool_call_id")) + fun toolCallId(): Optional = toolCallId.getOptional("tool_call_id") /** * Returns the raw JSON value of [role]. @@ -4251,8 +4244,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type (e.g. if the server responded with an unexpected value). */ - fun content(): Optional = - Optional.ofNullable(content.getNullable("content")) + fun content(): Optional = content.getOptional("content") /** * Returns the raw JSON value of [name]. @@ -4608,8 +4600,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected * type (e.g. if the server responded with an unexpected value). */ - fun content(): Optional = - Optional.ofNullable(content.getNullable("content")) + fun content(): Optional = content.getOptional("content") /** * Returns the raw JSON value of [role]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt index 812a03e8..4098a2a8 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt @@ -86,7 +86,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt index f6405594..d534335b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt @@ -18,6 +18,7 @@ import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor import java.util.function.Predicate +import kotlin.jvm.optionals.getOrNull /** * List out all prompts. The prompts are sorted by creation date, with the most recently-created @@ -88,7 +89,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptOptions.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptOptions.kt index 5cd212d0..92357d35 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptOptions.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptOptions.kt @@ -50,19 +50,19 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun model(): Optional = Optional.ofNullable(model.getNullable("model")) + fun model(): Optional = model.getOptional("model") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun params(): Optional = Optional.ofNullable(params.getNullable("params")) + fun params(): Optional = params.getOptional("params") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun position(): Optional = Optional.ofNullable(position.getNullable("position")) + fun position(): Optional = position.getOptional("position") /** * Returns the raw JSON value of [model]. @@ -558,14 +558,13 @@ private constructor( * if the server responded with an unexpected value). */ fun frequencyPenalty(): Optional = - Optional.ofNullable(frequencyPenalty.getNullable("frequency_penalty")) + frequencyPenalty.getOptional("frequency_penalty") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun functionCall(): Optional = - Optional.ofNullable(functionCall.getNullable("function_call")) + fun functionCall(): Optional = functionCall.getOptional("function_call") /** * The successor to max_tokens @@ -574,74 +573,70 @@ private constructor( * if the server responded with an unexpected value). */ fun maxCompletionTokens(): Optional = - Optional.ofNullable(maxCompletionTokens.getNullable("max_completion_tokens")) + maxCompletionTokens.getOptional("max_completion_tokens") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun maxTokens(): Optional = - Optional.ofNullable(maxTokens.getNullable("max_tokens")) + fun maxTokens(): Optional = maxTokens.getOptional("max_tokens") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun n(): Optional = Optional.ofNullable(n.getNullable("n")) + fun n(): Optional = n.getOptional("n") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ fun presencePenalty(): Optional = - Optional.ofNullable(presencePenalty.getNullable("presence_penalty")) + presencePenalty.getOptional("presence_penalty") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ fun reasoningEffort(): Optional = - Optional.ofNullable(reasoningEffort.getNullable("reasoning_effort")) + reasoningEffort.getOptional("reasoning_effort") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ fun responseFormat(): Optional = - Optional.ofNullable(responseFormat.getNullable("response_format")) + responseFormat.getOptional("response_format") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun stop(): Optional> = Optional.ofNullable(stop.getNullable("stop")) + fun stop(): Optional> = stop.getOptional("stop") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun temperature(): Optional = - Optional.ofNullable(temperature.getNullable("temperature")) + fun temperature(): Optional = temperature.getOptional("temperature") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun toolChoice(): Optional = - Optional.ofNullable(toolChoice.getNullable("tool_choice")) + fun toolChoice(): Optional = toolChoice.getOptional("tool_choice") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun topP(): Optional = Optional.ofNullable(topP.getNullable("top_p")) + fun topP(): Optional = topP.getOptional("top_p") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun useCache(): Optional = - Optional.ofNullable(useCache.getNullable("use_cache")) + fun useCache(): Optional = useCache.getOptional("use_cache") /** * Returns the raw JSON value of [frequencyPenalty]. @@ -2488,24 +2483,21 @@ private constructor( * unexpected type (e.g. if the server responded with an unexpected * value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * @throws BraintrustInvalidDataException if the JSON field has an * unexpected type (e.g. if the server responded with an unexpected * value). */ - fun schema(): Optional = - Optional.ofNullable(schema.getNullable("schema")) + fun schema(): Optional = schema.getOptional("schema") /** * @throws BraintrustInvalidDataException if the JSON field has an * unexpected type (e.g. if the server responded with an unexpected * value). */ - fun strict(): Optional = - Optional.ofNullable(strict.getNullable("strict")) + fun strict(): Optional = strict.getOptional("strict") /** * Returns the raw JSON value of [name]. @@ -4389,33 +4381,32 @@ private constructor( * if the server responded with an unexpected value). */ fun maxTokensToSample(): Optional = - Optional.ofNullable(maxTokensToSample.getNullable("max_tokens_to_sample")) + maxTokensToSample.getOptional("max_tokens_to_sample") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ fun stopSequences(): Optional> = - Optional.ofNullable(stopSequences.getNullable("stop_sequences")) + stopSequences.getOptional("stop_sequences") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun topK(): Optional = Optional.ofNullable(topK.getNullable("top_k")) + fun topK(): Optional = topK.getOptional("top_k") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun topP(): Optional = Optional.ofNullable(topP.getNullable("top_p")) + fun topP(): Optional = topP.getOptional("top_p") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun useCache(): Optional = - Optional.ofNullable(useCache.getNullable("use_cache")) + fun useCache(): Optional = useCache.getOptional("use_cache") /** * Returns the raw JSON value of [maxTokens]. @@ -4765,34 +4756,31 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun maxOutputTokens(): Optional = - Optional.ofNullable(maxOutputTokens.getNullable("maxOutputTokens")) + fun maxOutputTokens(): Optional = maxOutputTokens.getOptional("maxOutputTokens") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun temperature(): Optional = - Optional.ofNullable(temperature.getNullable("temperature")) + fun temperature(): Optional = temperature.getOptional("temperature") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun topK(): Optional = Optional.ofNullable(topK.getNullable("topK")) + fun topK(): Optional = topK.getOptional("topK") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun topP(): Optional = Optional.ofNullable(topP.getNullable("topP")) + fun topP(): Optional = topP.getOptional("topP") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun useCache(): Optional = - Optional.ofNullable(useCache.getNullable("use_cache")) + fun useCache(): Optional = useCache.getOptional("use_cache") /** * Returns the raw JSON value of [maxOutputTokens]. @@ -5054,21 +5042,19 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun temperature(): Optional = - Optional.ofNullable(temperature.getNullable("temperature")) + fun temperature(): Optional = temperature.getOptional("temperature") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun topK(): Optional = Optional.ofNullable(topK.getNullable("topK")) + fun topK(): Optional = topK.getOptional("topK") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun useCache(): Optional = - Optional.ofNullable(useCache.getNullable("use_cache")) + fun useCache(): Optional = useCache.getOptional("use_cache") /** * Returns the raw JSON value of [temperature]. @@ -5272,8 +5258,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. * if the server responded with an unexpected value). */ - fun useCache(): Optional = - Optional.ofNullable(useCache.getNullable("use_cache")) + fun useCache(): Optional = useCache.getOptional("use_cache") /** * Returns the raw JSON value of [useCache]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptReplaceParams.kt index d0e5c0d3..3274f771 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptReplaceParams.kt @@ -497,15 +497,13 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun functionType(): Optional = - Optional.ofNullable(functionType.getNullable("function_type")) + fun functionType(): Optional = functionType.getOptional("function_type") /** * The prompt, model, and its parameters @@ -513,8 +511,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun promptData(): Optional = - Optional.ofNullable(promptData.getNullable("prompt_data")) + fun promptData(): Optional = promptData.getOptional("prompt_data") /** * A list of tags for the prompt @@ -522,7 +519,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) + fun tags(): Optional> = tags.getOptional("tags") /** * Returns the raw JSON value of [name]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt index 7e9edc03..73422bc0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt @@ -426,8 +426,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * Name of the prompt @@ -435,7 +434,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun name(): Optional = name.getOptional("name") /** * The prompt, model, and its parameters @@ -443,8 +442,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun promptData(): Optional = - Optional.ofNullable(promptData.getNullable("prompt_data")) + fun promptData(): Optional = promptData.getOptional("prompt_data") /** * Unique identifier for the prompt @@ -452,7 +450,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun slug(): Optional = Optional.ofNullable(slug.getNullable("slug")) + fun slug(): Optional = slug.getOptional("slug") /** * A list of tags for the prompt @@ -460,7 +458,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun tags(): Optional> = Optional.ofNullable(tags.getNullable("tags")) + fun tags(): Optional> = tags.getOptional("tags") /** * Returns the raw JSON value of [description]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RepoInfo.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RepoInfo.kt index d4dd9d9c..d51766be 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RepoInfo.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RepoInfo.kt @@ -69,8 +69,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun authorEmail(): Optional = - Optional.ofNullable(authorEmail.getNullable("author_email")) + fun authorEmail(): Optional = authorEmail.getOptional("author_email") /** * Name of the author of the most recent commit @@ -78,7 +77,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun authorName(): Optional = Optional.ofNullable(authorName.getNullable("author_name")) + fun authorName(): Optional = authorName.getOptional("author_name") /** * Name of the branch the most recent commit belongs to @@ -86,7 +85,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun branch(): Optional = Optional.ofNullable(branch.getNullable("branch")) + fun branch(): Optional = branch.getOptional("branch") /** * SHA of most recent commit @@ -94,7 +93,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun commit(): Optional = Optional.ofNullable(commit.getNullable("commit")) + fun commit(): Optional = commit.getOptional("commit") /** * Most recent commit message @@ -102,8 +101,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun commitMessage(): Optional = - Optional.ofNullable(commitMessage.getNullable("commit_message")) + fun commitMessage(): Optional = commitMessage.getOptional("commit_message") /** * Time of the most recent commit @@ -111,7 +109,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun commitTime(): Optional = Optional.ofNullable(commitTime.getNullable("commit_time")) + fun commitTime(): Optional = commitTime.getOptional("commit_time") /** * Whether or not the repo had uncommitted changes when snapshotted @@ -119,7 +117,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun dirty(): Optional = Optional.ofNullable(dirty.getNullable("dirty")) + fun dirty(): Optional = dirty.getOptional("dirty") /** * If the repo was dirty when run, this includes the diff between the current state of the repo @@ -128,7 +126,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun gitDiff(): Optional = Optional.ofNullable(gitDiff.getNullable("git_diff")) + fun gitDiff(): Optional = gitDiff.getOptional("git_diff") /** * Name of the tag on the most recent commit @@ -136,7 +134,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun tag(): Optional = Optional.ofNullable(tag.getNullable("tag")) + fun tag(): Optional = tag.getOptional("tag") /** * Returns the raw JSON value of [authorEmail]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Role.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Role.kt index a977c315..f55b44e3 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Role.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Role.kt @@ -95,7 +95,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun created(): Optional = Optional.ofNullable(created.getNullable("created")) + fun created(): Optional = created.getOptional("created") /** * Date of role deletion, or null if the role is still active @@ -103,8 +103,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun deletedAt(): Optional = - Optional.ofNullable(deletedAt.getNullable("deleted_at")) + fun deletedAt(): Optional = deletedAt.getOptional("deleted_at") /** * Textual description of the role @@ -112,8 +111,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * (permission, restrict_object_type) tuples which belong to this role @@ -122,7 +120,7 @@ private constructor( * server responded with an unexpected value). */ fun memberPermissions(): Optional> = - Optional.ofNullable(memberPermissions.getNullable("member_permissions")) + memberPermissions.getOptional("member_permissions") /** * Ids of the roles this role inherits from @@ -133,8 +131,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun memberRoles(): Optional> = - Optional.ofNullable(memberRoles.getNullable("member_roles")) + fun memberRoles(): Optional> = memberRoles.getOptional("member_roles") /** * Unique id for the organization that the role belongs under @@ -147,7 +144,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun orgId(): Optional = Optional.ofNullable(orgId.getNullable("org_id")) + fun orgId(): Optional = orgId.getOptional("org_id") /** * Identifies the user who created the role @@ -155,7 +152,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) + fun userId(): Optional = userId.getOptional("user_id") /** * Returns the raw JSON value of [id]. @@ -573,7 +570,7 @@ private constructor( * the server responded with an unexpected value). */ fun restrictObjectType(): Optional = - Optional.ofNullable(restrictObjectType.getNullable("restrict_object_type")) + restrictObjectType.getOptional("restrict_object_type") /** * Returns the raw JSON value of [permission]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleCreateParams.kt index 86557ac1..4e8526c6 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleCreateParams.kt @@ -443,8 +443,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * (permission, restrict_object_type) tuples which belong to this role @@ -453,7 +452,7 @@ private constructor( * the server responded with an unexpected value). */ fun memberPermissions(): Optional> = - Optional.ofNullable(memberPermissions.getNullable("member_permissions")) + memberPermissions.getOptional("member_permissions") /** * Ids of the roles this role inherits from @@ -464,8 +463,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun memberRoles(): Optional> = - Optional.ofNullable(memberRoles.getNullable("member_roles")) + fun memberRoles(): Optional> = memberRoles.getOptional("member_roles") /** * For nearly all users, this parameter should be unnecessary. But in the rare case that @@ -475,7 +473,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) + fun orgName(): Optional = orgName.getOptional("org_name") /** * Returns the raw JSON value of [name]. @@ -812,7 +810,7 @@ private constructor( * the server responded with an unexpected value). */ fun restrictObjectType(): Optional = - Optional.ofNullable(restrictObjectType.getNullable("restrict_object_type")) + restrictObjectType.getOptional("restrict_object_type") /** * Returns the raw JSON value of [permission]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt index 37e67991..9449de10 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt @@ -86,7 +86,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt index 6c637a90..1c36629f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt @@ -18,6 +18,7 @@ import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor import java.util.function.Predicate +import kotlin.jvm.optionals.getOrNull /** * List out all roles. The roles are sorted by creation date, with the most recently-created roles @@ -88,7 +89,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleReplaceParams.kt index 0a787253..791e3fd8 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleReplaceParams.kt @@ -447,8 +447,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * (permission, restrict_object_type) tuples which belong to this role @@ -457,7 +456,7 @@ private constructor( * the server responded with an unexpected value). */ fun memberPermissions(): Optional> = - Optional.ofNullable(memberPermissions.getNullable("member_permissions")) + memberPermissions.getOptional("member_permissions") /** * Ids of the roles this role inherits from @@ -468,8 +467,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun memberRoles(): Optional> = - Optional.ofNullable(memberRoles.getNullable("member_roles")) + fun memberRoles(): Optional> = memberRoles.getOptional("member_roles") /** * For nearly all users, this parameter should be unnecessary. But in the rare case that @@ -479,7 +477,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun orgName(): Optional = Optional.ofNullable(orgName.getNullable("org_name")) + fun orgName(): Optional = orgName.getOptional("org_name") /** * Returns the raw JSON value of [name]. @@ -816,7 +814,7 @@ private constructor( * the server responded with an unexpected value). */ fun restrictObjectType(): Optional = - Optional.ofNullable(restrictObjectType.getNullable("restrict_object_type")) + restrictObjectType.getOptional("restrict_object_type") /** * Returns the raw JSON value of [permission]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleUpdateParams.kt index 0e650f99..390da928 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleUpdateParams.kt @@ -535,7 +535,7 @@ private constructor( * the server responded with an unexpected value). */ fun addMemberPermissions(): Optional> = - Optional.ofNullable(addMemberPermissions.getNullable("add_member_permissions")) + addMemberPermissions.getOptional("add_member_permissions") /** * A list of role IDs to add to the role's inheriting-from set @@ -544,7 +544,7 @@ private constructor( * the server responded with an unexpected value). */ fun addMemberRoles(): Optional> = - Optional.ofNullable(addMemberRoles.getNullable("add_member_roles")) + addMemberRoles.getOptional("add_member_roles") /** * Textual description of the role @@ -552,8 +552,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * Name of the role @@ -561,7 +560,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun name(): Optional = name.getOptional("name") /** * A list of permissions to remove from the role @@ -570,7 +569,7 @@ private constructor( * the server responded with an unexpected value). */ fun removeMemberPermissions(): Optional> = - Optional.ofNullable(removeMemberPermissions.getNullable("remove_member_permissions")) + removeMemberPermissions.getOptional("remove_member_permissions") /** * A list of role IDs to remove from the role's inheriting-from set @@ -579,7 +578,7 @@ private constructor( * the server responded with an unexpected value). */ fun removeMemberRoles(): Optional> = - Optional.ofNullable(removeMemberRoles.getNullable("remove_member_roles")) + removeMemberRoles.getOptional("remove_member_roles") /** * Returns the raw JSON value of [addMemberPermissions]. @@ -975,7 +974,7 @@ private constructor( * the server responded with an unexpected value). */ fun restrictObjectType(): Optional = - Optional.ofNullable(restrictObjectType.getNullable("restrict_object_type")) + restrictObjectType.getOptional("restrict_object_type") /** * Returns the raw JSON value of [permission]. @@ -1198,7 +1197,7 @@ private constructor( * the server responded with an unexpected value). */ fun restrictObjectType(): Optional = - Optional.ofNullable(restrictObjectType.getNullable("restrict_object_type")) + restrictObjectType.getOptional("restrict_object_type") /** * Returns the raw JSON value of [permission]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ScoreSummary.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ScoreSummary.kt index bd494f33..207b7123 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ScoreSummary.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ScoreSummary.kt @@ -78,7 +78,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun diff(): Optional = Optional.ofNullable(diff.getNullable("diff")) + fun diff(): Optional = diff.getOptional("diff") /** * Returns the raw JSON value of [improvements]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanAttributes.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanAttributes.kt index 21bd09b0..13b88570 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanAttributes.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanAttributes.kt @@ -36,7 +36,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun name(): Optional = name.getOptional("name") /** * Type of the span, for display purposes only @@ -44,7 +44,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun type(): Optional = Optional.ofNullable(type.getNullable("type")) + fun type(): Optional = type.getOptional("type") /** * Returns the raw JSON value of [name]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIFrame.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIFrame.kt index 4d67a41a..65ede1b3 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIFrame.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIFrame.kt @@ -102,7 +102,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun created(): Optional = Optional.ofNullable(created.getNullable("created")) + fun created(): Optional = created.getOptional("created") /** * Date of span iframe deletion, or null if the span iframe is still active @@ -110,8 +110,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun deletedAt(): Optional = - Optional.ofNullable(deletedAt.getNullable("deleted_at")) + fun deletedAt(): Optional = deletedAt.getOptional("deleted_at") /** * Textual description of the span iframe @@ -119,8 +118,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * Whether to post messages to the iframe containing the span's data. This is useful when you @@ -129,8 +127,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun postMessage(): Optional = - Optional.ofNullable(postMessage.getNullable("post_message")) + fun postMessage(): Optional = postMessage.getOptional("post_message") /** * Identifies the user who created the span iframe @@ -138,7 +135,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) + fun userId(): Optional = userId.getOptional("user_id") /** * Returns the raw JSON value of [id]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeCreateParams.kt index 942eeb94..8d2e050d 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeCreateParams.kt @@ -432,8 +432,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * Whether to post messages to the iframe containing the span's data. This is useful when @@ -442,8 +441,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun postMessage(): Optional = - Optional.ofNullable(postMessage.getNullable("post_message")) + fun postMessage(): Optional = postMessage.getOptional("post_message") /** * Returns the raw JSON value of [name]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt index ac913dfe..0fa817b5 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt @@ -89,7 +89,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt index 3f6112ce..2a5e98a8 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt @@ -18,6 +18,7 @@ import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor import java.util.function.Predicate +import kotlin.jvm.optionals.getOrNull /** * List out all span_iframes. The span_iframes are sorted by creation date, with the most @@ -91,7 +92,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeReplaceParams.kt index d089176c..5b2265b4 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeReplaceParams.kt @@ -432,8 +432,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * Whether to post messages to the iframe containing the span's data. This is useful when @@ -442,8 +441,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun postMessage(): Optional = - Optional.ofNullable(postMessage.getNullable("post_message")) + fun postMessage(): Optional = postMessage.getOptional("post_message") /** * Returns the raw JSON value of [name]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParams.kt index bcaab7e6..7236e5a9 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParams.kt @@ -394,8 +394,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) + fun description(): Optional = description.getOptional("description") /** * Name of the span iframe @@ -403,7 +402,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun name(): Optional = name.getOptional("name") /** * Whether to post messages to the iframe containing the span's data. This is useful when @@ -412,8 +411,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun postMessage(): Optional = - Optional.ofNullable(postMessage.getNullable("post_message")) + fun postMessage(): Optional = postMessage.getOptional("post_message") /** * URL to embed the project viewer in an iframe @@ -421,7 +419,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun url(): Optional = Optional.ofNullable(url.getNullable("url")) + fun url(): Optional = url.getOptional("url") /** * Returns the raw JSON value of [description]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SummarizeDatasetResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SummarizeDatasetResponse.kt index c3512b1d..4f09f443 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SummarizeDatasetResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SummarizeDatasetResponse.kt @@ -85,8 +85,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun dataSummary(): Optional = - Optional.ofNullable(dataSummary.getNullable("data_summary")) + fun dataSummary(): Optional = dataSummary.getOptional("data_summary") /** * Returns the raw JSON value of [datasetName]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SummarizeExperimentResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SummarizeExperimentResponse.kt index fddeab3c..05066a50 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SummarizeExperimentResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SummarizeExperimentResponse.kt @@ -100,7 +100,7 @@ private constructor( * server responded with an unexpected value). */ fun comparisonExperimentName(): Optional = - Optional.ofNullable(comparisonExperimentName.getNullable("comparison_experiment_name")) + comparisonExperimentName.getOptional("comparison_experiment_name") /** * Summary of the experiment's metrics @@ -108,7 +108,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun metrics(): Optional = Optional.ofNullable(metrics.getNullable("metrics")) + fun metrics(): Optional = metrics.getOptional("metrics") /** * Summary of the experiment's scores @@ -116,7 +116,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun scores(): Optional = Optional.ofNullable(scores.getNullable("scores")) + fun scores(): Optional = scores.getOptional("scores") /** * Returns the raw JSON value of [experimentName]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/User.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/User.kt index 317fbc17..d2a2db23 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/User.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/User.kt @@ -57,7 +57,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun avatarUrl(): Optional = Optional.ofNullable(avatarUrl.getNullable("avatar_url")) + fun avatarUrl(): Optional = avatarUrl.getOptional("avatar_url") /** * Date of user creation @@ -65,7 +65,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun created(): Optional = Optional.ofNullable(created.getNullable("created")) + fun created(): Optional = created.getOptional("created") /** * The user's email @@ -73,7 +73,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun email(): Optional = Optional.ofNullable(email.getNullable("email")) + fun email(): Optional = email.getOptional("email") /** * Family name of the user @@ -81,7 +81,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun familyName(): Optional = Optional.ofNullable(familyName.getNullable("family_name")) + fun familyName(): Optional = familyName.getOptional("family_name") /** * Given name of the user @@ -89,7 +89,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun givenName(): Optional = Optional.ofNullable(givenName.getNullable("given_name")) + fun givenName(): Optional = givenName.getOptional("given_name") /** * Returns the raw JSON value of [id]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt index ce3e3325..0b685152 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt @@ -86,7 +86,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt index fa4e3654..57c87b9d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt @@ -18,6 +18,7 @@ import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor import java.util.function.Predicate +import kotlin.jvm.optionals.getOrNull /** * List out all users. The users are sorted by creation date, with the most recently-created users @@ -88,7 +89,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/View.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/View.kt index 82c22250..5ca9dc21 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/View.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/View.kt @@ -104,7 +104,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun viewType(): Optional = Optional.ofNullable(viewType.getNullable("view_type")) + fun viewType(): Optional = viewType.getOptional("view_type") /** * Date of view creation @@ -112,7 +112,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun created(): Optional = Optional.ofNullable(created.getNullable("created")) + fun created(): Optional = created.getOptional("created") /** * Date of role deletion, or null if the role is still active @@ -120,8 +120,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun deletedAt(): Optional = - Optional.ofNullable(deletedAt.getNullable("deleted_at")) + fun deletedAt(): Optional = deletedAt.getOptional("deleted_at") /** * Options for the view in the app @@ -129,7 +128,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun options(): Optional = Optional.ofNullable(options.getNullable("options")) + fun options(): Optional = options.getOptional("options") /** * Identifies the user who created the view @@ -137,7 +136,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) + fun userId(): Optional = userId.getOptional("user_id") /** * The view definition @@ -145,7 +144,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun viewData(): Optional = Optional.ofNullable(viewData.getNullable("view_data")) + fun viewData(): Optional = viewData.getOptional("view_data") /** * Returns the raw JSON value of [id]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewCreateParams.kt index 2dfdfdb1..608ecf69 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewCreateParams.kt @@ -532,7 +532,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun viewType(): Optional = Optional.ofNullable(viewType.getNullable("view_type")) + fun viewType(): Optional = viewType.getOptional("view_type") /** * Date of role deletion, or null if the role is still active @@ -540,8 +540,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun deletedAt(): Optional = - Optional.ofNullable(deletedAt.getNullable("deleted_at")) + fun deletedAt(): Optional = deletedAt.getOptional("deleted_at") /** * Options for the view in the app @@ -549,7 +548,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun options(): Optional = Optional.ofNullable(options.getNullable("options")) + fun options(): Optional = options.getOptional("options") /** * Identifies the user who created the view @@ -557,7 +556,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) + fun userId(): Optional = userId.getOptional("user_id") /** * The view definition @@ -565,7 +564,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun viewData(): Optional = Optional.ofNullable(viewData.getNullable("view_data")) + fun viewData(): Optional = viewData.getOptional("view_data") /** * Returns the raw JSON value of [name]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewData.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewData.kt index f9e772d0..ebc6ae84 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewData.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewData.kt @@ -32,7 +32,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun search(): Optional = Optional.ofNullable(search.getNullable("search")) + fun search(): Optional = search.getOptional("search") /** * Returns the raw JSON value of [search]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDataSearch.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDataSearch.kt index 5907303b..3868ec17 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDataSearch.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDataSearch.kt @@ -43,25 +43,25 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun filter(): Optional> = Optional.ofNullable(filter.getNullable("filter")) + fun filter(): Optional> = filter.getOptional("filter") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun match(): Optional> = Optional.ofNullable(match.getNullable("match")) + fun match(): Optional> = match.getOptional("match") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun sort(): Optional> = Optional.ofNullable(sort.getNullable("sort")) + fun sort(): Optional> = sort.getOptional("sort") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun tag(): Optional> = Optional.ofNullable(tag.getNullable("tag")) + fun tag(): Optional> = tag.getOptional("tag") /** * Returns the raw JSON value of [filter]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt index d460ef58..4f443811 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt @@ -86,7 +86,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt index cdaed4f6..84a2bd26 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt @@ -18,6 +18,7 @@ import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor import java.util.function.Predicate +import kotlin.jvm.optionals.getOrNull /** * List out all views. The views are sorted by creation date, with the most recently-created views @@ -88,7 +89,7 @@ private constructor( @JsonProperty("objects") objects: JsonField> = JsonMissing.of() ) : this(objects, mutableMapOf()) - fun objects(): List = objects.getNullable("objects") ?: listOf() + fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() @JsonProperty("objects") fun _objects(): Optional>> = Optional.ofNullable(objects) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewOptions.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewOptions.kt index 4b2f9aeb..2a50e44b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewOptions.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewOptions.kt @@ -58,40 +58,38 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun columnOrder(): Optional> = - Optional.ofNullable(columnOrder.getNullable("columnOrder")) + fun columnOrder(): Optional> = columnOrder.getOptional("columnOrder") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun columnSizing(): Optional = - Optional.ofNullable(columnSizing.getNullable("columnSizing")) + fun columnSizing(): Optional = columnSizing.getOptional("columnSizing") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ fun columnVisibility(): Optional = - Optional.ofNullable(columnVisibility.getNullable("columnVisibility")) + columnVisibility.getOptional("columnVisibility") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun grouping(): Optional = Optional.ofNullable(grouping.getNullable("grouping")) + fun grouping(): Optional = grouping.getOptional("grouping") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun layout(): Optional = Optional.ofNullable(layout.getNullable("layout")) + fun layout(): Optional = layout.getOptional("layout") /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun rowHeight(): Optional = Optional.ofNullable(rowHeight.getNullable("rowHeight")) + fun rowHeight(): Optional = rowHeight.getOptional("rowHeight") /** * Returns the raw JSON value of [columnOrder]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewReplaceParams.kt index 51980717..1f5303d5 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewReplaceParams.kt @@ -536,7 +536,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun viewType(): Optional = Optional.ofNullable(viewType.getNullable("view_type")) + fun viewType(): Optional = viewType.getOptional("view_type") /** * Date of role deletion, or null if the role is still active @@ -544,8 +544,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun deletedAt(): Optional = - Optional.ofNullable(deletedAt.getNullable("deleted_at")) + fun deletedAt(): Optional = deletedAt.getOptional("deleted_at") /** * Options for the view in the app @@ -553,7 +552,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun options(): Optional = Optional.ofNullable(options.getNullable("options")) + fun options(): Optional = options.getOptional("options") /** * Identifies the user who created the view @@ -561,7 +560,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) + fun userId(): Optional = userId.getOptional("user_id") /** * The view definition @@ -569,7 +568,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun viewData(): Optional = Optional.ofNullable(viewData.getNullable("view_data")) + fun viewData(): Optional = viewData.getOptional("view_data") /** * Returns the raw JSON value of [name]. diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewUpdateParams.kt index eba7a3d0..389a485f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewUpdateParams.kt @@ -501,7 +501,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + fun name(): Optional = name.getOptional("name") /** * Options for the view in the app @@ -509,7 +509,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun options(): Optional = Optional.ofNullable(options.getNullable("options")) + fun options(): Optional = options.getOptional("options") /** * Identifies the user who created the view @@ -517,7 +517,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun userId(): Optional = Optional.ofNullable(userId.getNullable("user_id")) + fun userId(): Optional = userId.getOptional("user_id") /** * The view definition @@ -525,7 +525,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun viewData(): Optional = Optional.ofNullable(viewData.getNullable("view_data")) + fun viewData(): Optional = viewData.getOptional("view_data") /** * Type of table that the view corresponds to. @@ -533,7 +533,7 @@ private constructor( * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun viewType(): Optional = Optional.ofNullable(viewType.getNullable("view_type")) + fun viewType(): Optional = viewType.getOptional("view_type") /** * Returns the raw JSON value of [objectId]. From e3d5b190c14a9f398bfed2b8df461d01b411c1f3 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 4 Apr 2025 23:59:15 +0000 Subject: [PATCH 28/42] fix(client): return `Optional` instead of `Optional` (#182) docs: add comments to `JsonField` classes --- .../com/braintrustdata/api/core/Values.kt | 237 ++++++++++++++++-- 1 file changed, 218 insertions(+), 19 deletions(-) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Values.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Values.kt index b24237d3..7f71390d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Values.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Values.kt @@ -29,30 +29,51 @@ import java.io.InputStream import java.util.Objects import java.util.Optional +/** + * A class representing a serializable JSON field. + * + * It can either be a [KnownValue] value of type [T], matching the type the SDK expects, or an + * arbitrary JSON value that bypasses the type system (via [JsonValue]). + */ @JsonDeserialize(using = JsonField.Deserializer::class) sealed class JsonField { + /** + * Returns whether this field is missing, which means it will be omitted from the serialized + * JSON entirely. + */ fun isMissing(): Boolean = this is JsonMissing + /** Whether this field is explicitly set to `null`. */ fun isNull(): Boolean = this is JsonNull - fun asKnown(): Optional = - when (this) { - is KnownValue -> Optional.of(value) - else -> Optional.empty() - } + /** + * Returns an [Optional] containing this field's "known" value, meaning it matches the type the + * SDK expects, or an empty [Optional] if this field contains an arbitrary [JsonValue]. + * + * This is the opposite of [asUnknown]. + */ + fun asKnown(): + Optional< + // Safe because `Optional` is effectively covariant, but Kotlin doesn't know that. + @UnsafeVariance + T + > = Optional.ofNullable((this as? KnownValue)?.value) /** - * If the "known" value (i.e. matching the type that the SDK expects) is returned by the API - * then this method will return an empty `Optional`, otherwise the returned `Optional` is given - * a `JsonValue`. + * Returns an [Optional] containing this field's arbitrary [JsonValue], meaning it mismatches + * the type the SDK expects, or an empty [Optional] if this field contains a "known" value. + * + * This is the opposite of [asKnown]. */ - fun asUnknown(): Optional = - when (this) { - is JsonValue -> Optional.of(this) - else -> Optional.empty() - } + fun asUnknown(): Optional = Optional.ofNullable(this as? JsonValue) + /** + * Returns an [Optional] containing this field's boolean value, or an empty [Optional] if it + * doesn't contain a boolean. + * + * This method checks for both a [KnownValue] containing a boolean and for [JsonBoolean]. + */ fun asBoolean(): Optional = when (this) { is JsonBoolean -> Optional.of(value) @@ -60,6 +81,12 @@ sealed class JsonField { else -> Optional.empty() } + /** + * Returns an [Optional] containing this field's numerical value, or an empty [Optional] if it + * doesn't contain a number. + * + * This method checks for both a [KnownValue] containing a number and for [JsonNumber]. + */ fun asNumber(): Optional = when (this) { is JsonNumber -> Optional.of(value) @@ -67,6 +94,12 @@ sealed class JsonField { else -> Optional.empty() } + /** + * Returns an [Optional] containing this field's string value, or an empty [Optional] if it + * doesn't contain a string. + * + * This method checks for both a [KnownValue] containing a string and for [JsonString]. + */ fun asString(): Optional = when (this) { is JsonString -> Optional.of(value) @@ -77,6 +110,12 @@ sealed class JsonField { fun asStringOrThrow(): String = asString().orElseThrow { BraintrustInvalidDataException("Value is not a string") } + /** + * Returns an [Optional] containing this field's list value, or an empty [Optional] if it + * doesn't contain a list. + * + * This method checks for both a [KnownValue] containing a list and for [JsonArray]. + */ fun asArray(): Optional> = when (this) { is JsonArray -> Optional.of(values) @@ -95,6 +134,12 @@ sealed class JsonField { else -> Optional.empty() } + /** + * Returns an [Optional] containing this field's map value, or an empty [Optional] if it doesn't + * contain a map. + * + * This method checks for both a [KnownValue] containing a map and for [JsonObject]. + */ fun asObject(): Optional> = when (this) { is JsonObject -> Optional.of(values) @@ -132,7 +177,13 @@ sealed class JsonField { } @JvmSynthetic - internal fun getOptional(name: String): Optional<@UnsafeVariance T> = + internal fun getOptional( + name: String + ): Optional< + // Safe because `Optional` is effectively covariant, but Kotlin doesn't know that. + @UnsafeVariance + T + > = when (this) { is KnownValue -> Optional.of(value) is JsonMissing, @@ -147,21 +198,33 @@ sealed class JsonField { is JsonValue -> this } - @JvmSynthetic fun accept(consume: (T) -> Unit) = asKnown().ifPresent(consume) + @JvmSynthetic internal fun accept(consume: (T) -> Unit) = asKnown().ifPresent(consume) + /** Returns the result of calling the [visitor] method corresponding to this field's state. */ fun accept(visitor: Visitor): R = when (this) { is KnownValue -> visitor.visitKnown(value) is JsonValue -> accept(visitor as JsonValue.Visitor) } + /** + * An interface that defines how to map each possible state of a `JsonField` to a value of + * type [R]. + */ interface Visitor : JsonValue.Visitor { + fun visitKnown(value: T): R = visitDefault() } companion object { + + /** Returns a [JsonField] containing the given "known" [value]. */ @JvmStatic fun of(value: T): JsonField = KnownValue.of(value) + /** + * Returns a [JsonField] containing the given "known" [value], or [JsonNull] if [value] is + * null. + */ @JvmStatic fun ofNullable(value: T?): JsonField = when (value) { @@ -176,6 +239,7 @@ sealed class JsonField { * annotation. */ class IsMissing { + override fun equals(other: Any?): Boolean = other is JsonMissing override fun hashCode(): Int = Objects.hash() @@ -197,6 +261,12 @@ sealed class JsonField { } } +/** + * A class representing an arbitrary JSON value. + * + * It is immutable and assignable to any [JsonField], regardless of its expected type (i.e. its + * generic type argument). + */ @JsonDeserialize(using = JsonValue.Deserializer::class) sealed class JsonValue : JsonField() { @@ -204,6 +274,7 @@ sealed class JsonValue : JsonField() { fun convert(type: Class): R? = JSON_MAPPER.convertValue(this, type) + /** Returns the result of calling the [visitor] method corresponding to this value's variant. */ fun accept(visitor: Visitor): R = when (this) { is JsonMissing -> visitor.visitMissing() @@ -215,7 +286,12 @@ sealed class JsonValue : JsonField() { is JsonObject -> visitor.visitObject(values) } + /** + * An interface that defines how to map each variant state of a [JsonValue] to a value of type + * [R]. + */ interface Visitor { + fun visitNull(): R = visitDefault() fun visitMissing(): R = visitDefault() @@ -230,15 +306,52 @@ sealed class JsonValue : JsonField() { fun visitObject(values: Map): R = visitDefault() - fun visitDefault(): R { - throw RuntimeException("Unexpected value") - } + /** + * The default implementation for unimplemented visitor methods. + * + * @throws IllegalArgumentException in the default implementation. + */ + fun visitDefault(): R = throw IllegalArgumentException("Unexpected value") } companion object { private val JSON_MAPPER = jsonMapper() + /** + * Converts the given [value] to a [JsonValue]. + * + * This method works best on primitive types, [List] values, [Map] values, and nested + * combinations of these. For example: + * ```java + * // Create primitive JSON values + * JsonValue nullValue = JsonValue.from(null); + * JsonValue booleanValue = JsonValue.from(true); + * JsonValue numberValue = JsonValue.from(42); + * JsonValue stringValue = JsonValue.from("Hello World!"); + * + * // Create a JSON array value equivalent to `["Hello", "World"]` + * JsonValue arrayValue = JsonValue.from(List.of("Hello", "World")); + * + * // Create a JSON object value equivalent to `{ "a": 1, "b": 2 }` + * JsonValue objectValue = JsonValue.from(Map.of( + * "a", 1, + * "b", 2 + * )); + * + * // Create an arbitrarily nested JSON equivalent to: + * // { + * // "a": [1, 2], + * // "b": [3, 4] + * // } + * JsonValue complexValue = JsonValue.from(Map.of( + * "a", List.of(1, 2), + * "b", List.of(3, 4) + * )); + * ``` + * + * @throws IllegalArgumentException if [value] is not JSON serializable. + */ @JvmStatic fun from(value: Any?): JsonValue = when (value) { @@ -247,6 +360,11 @@ sealed class JsonValue : JsonField() { else -> JSON_MAPPER.convertValue(value, JsonValue::class.java) } + /** + * Returns a [JsonValue] converted from the given Jackson [JsonNode]. + * + * @throws IllegalStateException for unsupported node types. + */ @JvmStatic fun fromJsonNode(node: JsonNode): JsonValue = when (node.nodeType) { @@ -268,12 +386,19 @@ sealed class JsonValue : JsonField() { } class Deserializer : BaseDeserializer(JsonValue::class) { + override fun ObjectCodec.deserialize(node: JsonNode): JsonValue = fromJsonNode(node) override fun getNullValue(context: DeserializationContext?): JsonValue = JsonNull.of() } } +/** + * A class representing a "known" JSON serializable value of type [T], matching the type the SDK + * expects. + * + * It is assignable to `JsonField`. + */ class KnownValue private constructor( @com.fasterxml.jackson.annotation.JsonValue @get:JvmName("value") val value: T @@ -292,44 +417,59 @@ private constructor( override fun toString() = value.contentToString() companion object { + + /** Returns a [KnownValue] containing the given [value]. */ @JsonCreator @JvmStatic fun of(value: T) = KnownValue(value) } } +/** + * A [JsonValue] representing an omitted JSON field. + * + * An instance of this class will cause a JSON field to be omitted from the serialized JSON + * entirely. + */ @JsonSerialize(using = JsonMissing.Serializer::class) class JsonMissing : JsonValue() { override fun toString() = "" companion object { + private val INSTANCE: JsonMissing = JsonMissing() + /** Returns the singleton instance of [JsonMissing]. */ @JvmStatic fun of() = INSTANCE } class Serializer : BaseSerializer(JsonMissing::class) { + override fun serialize( value: JsonMissing, generator: JsonGenerator, provider: SerializerProvider, ) { - throw RuntimeException("JsonMissing cannot be serialized") + throw IllegalStateException("JsonMissing cannot be serialized") } } } +/** A [JsonValue] representing a JSON `null` value. */ @JsonSerialize(using = NullSerializer::class) class JsonNull : JsonValue() { override fun toString() = "null" companion object { + private val INSTANCE: JsonNull = JsonNull() + /** Returns the singleton instance of [JsonMissing]. */ @JsonCreator @JvmStatic fun of() = INSTANCE } } +/** A [JsonValue] representing a JSON boolean value. */ class JsonBoolean private constructor( @get:com.fasterxml.jackson.annotation.JsonValue @get:JvmName("value") val value: Boolean @@ -348,14 +488,18 @@ private constructor( override fun toString() = value.toString() companion object { + + /** Returns a [JsonBoolean] containing the given [value]. */ @JsonCreator @JvmStatic fun of(value: Boolean) = JsonBoolean(value) } } +/** A [JsonValue] representing a JSON number value. */ class JsonNumber private constructor( @get:com.fasterxml.jackson.annotation.JsonValue @get:JvmName("value") val value: Number ) : JsonValue() { + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -369,10 +513,13 @@ private constructor( override fun toString() = value.toString() companion object { + + /** Returns a [JsonNumber] containing the given [value]. */ @JsonCreator @JvmStatic fun of(value: Number) = JsonNumber(value) } } +/** A [JsonValue] representing a JSON string value. */ class JsonString private constructor( @get:com.fasterxml.jackson.annotation.JsonValue @get:JvmName("value") val value: String @@ -391,10 +538,13 @@ private constructor( override fun toString() = value companion object { + + /** Returns a [JsonString] containing the given [value]. */ @JsonCreator @JvmStatic fun of(value: String) = JsonString(value) } } +/** A [JsonValue] representing a JSON array value. */ class JsonArray private constructor( @get:com.fasterxml.jackson.annotation.JsonValue @@ -415,10 +565,13 @@ private constructor( override fun toString() = values.toString() companion object { + + /** Returns a [JsonArray] containing the given [values]. */ @JsonCreator @JvmStatic fun of(values: List) = JsonArray(values.toImmutable()) } } +/** A [JsonValue] representing a JSON object value. */ class JsonObject private constructor( @get:com.fasterxml.jackson.annotation.JsonValue @@ -439,32 +592,62 @@ private constructor( override fun toString() = values.toString() companion object { + + /** Returns a [JsonObject] containing the given [values]. */ @JsonCreator @JvmStatic fun of(values: Map) = JsonObject(values.toImmutable()) } } +/** A Jackson annotation for excluding fields set to [JsonMissing] from the serialized JSON. */ @JacksonAnnotationsInside @JsonInclude(JsonInclude.Include.CUSTOM, valueFilter = JsonField.IsMissing::class) annotation class ExcludeMissing +/** A class representing a field in a `multipart/form-data` request. */ class MultipartField private constructor( + /** A [JsonField] value, which will be serialized to zero or more parts. */ @get:com.fasterxml.jackson.annotation.JsonValue @get:JvmName("value") val value: JsonField, + /** A content type for the serialized parts. */ @get:JvmName("contentType") val contentType: String, private val filename: String?, ) { companion object { + /** + * Returns a [MultipartField] containing the given [value] as a [KnownValue]. + * + * [contentType] will be set to `application/octet-stream` if [value] is binary data, or + * `text/plain; charset=utf-8` otherwise. + */ @JvmStatic fun of(value: T?) = builder().value(value).build() + /** + * Returns a [MultipartField] containing the given [value]. + * + * [contentType] will be set to `application/octet-stream` if [value] is binary data, or + * `text/plain; charset=utf-8` otherwise. + */ @JvmStatic fun of(value: JsonField) = builder().value(value).build() + /** + * Returns a mutable builder for constructing an instance of [MultipartField]. + * + * The following fields are required: + * ```java + * .value() + * ``` + * + * If [contentType] is unset, then it will be set to `application/octet-stream` if [value] + * is binary data, or `text/plain; charset=utf-8` otherwise. + */ @JvmStatic fun builder() = Builder() } + /** Returns the filename directive that will be included in the serialized field. */ fun filename(): Optional = Optional.ofNullable(filename) @JvmSynthetic @@ -486,8 +669,24 @@ private constructor( fun filename(filename: String?) = apply { this.filename = filename } + /** Alias for calling [Builder.filename] with `filename.orElse(null)`. */ fun filename(filename: Optional) = filename(filename.orElse(null)) + /** + * Returns an immutable instance of [MultipartField]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .value() + * ``` + * + * If [contentType] is unset, then it will be set to `application/octet-stream` if [value] + * is binary data, or `text/plain; charset=utf-8` otherwise. + * + * @throws IllegalStateException if any required field is unset. + */ fun build(): MultipartField { val value = checkRequired("value", value) return MultipartField( From e797de1a9185adb1dab8f9670fd2d8e4b03e2142 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 5 Apr 2025 00:09:31 +0000 Subject: [PATCH 29/42] docs: swap examples used in readme (#183) docs: document how to forcibly omit required field --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index f32eedab..8c5046c2 100644 --- a/README.md +++ b/README.md @@ -445,6 +445,19 @@ JsonValue complexValue = JsonValue.from(Map.of( )); ``` +Normally a `Builder` class's `build` method will throw [`IllegalStateException`](https://docs.oracle.com/javase/8/docs/api/java/lang/IllegalStateException.html) if any required parameter or property is unset. + +To forcibly omit a required parameter or property, pass [`JsonMissing`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Values.kt): + +```java +import com.braintrustdata.api.core.JsonMissing; +import com.braintrustdata.api.models.ProjectCreateParams; + +ProjectCreateParams params = ProjectCreateParams.builder() + .name(JsonMissing.of()) + .build(); +``` + ### Response properties To access undocumented response properties, call the `_additionalProperties()` method: From 85b334ae4ce795835275970643f930468753d57a Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 10 Apr 2025 03:34:21 +0000 Subject: [PATCH 30/42] feat(client): support setting base URL via env var --- README.md | 17 +++++++++-------- .../api/client/okhttp/BraintrustOkHttpClient.kt | 8 ++------ .../okhttp/BraintrustOkHttpClientAsync.kt | 8 ++------ .../braintrustdata/api/core/ClientOptions.kt | 7 ++++++- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 8c5046c2..a08df254 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient; import com.braintrustdata.api.models.Project; import com.braintrustdata.api.models.ProjectCreateParams; -// Configures using the `BRAINTRUST_API_KEY` environment variable +// Configures using the `BRAINTRUST_API_KEY` and `BRAINTRUST_BASE_URL` environment variables BraintrustClient client = BraintrustOkHttpClient.fromEnv(); ProjectCreateParams params = ProjectCreateParams.builder() @@ -70,7 +70,7 @@ Configure the client using environment variables: import com.braintrustdata.api.client.BraintrustClient; import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient; -// Configures using the `BRAINTRUST_API_KEY` environment variable +// Configures using the `BRAINTRUST_API_KEY` and `BRAINTRUST_BASE_URL` environment variables BraintrustClient client = BraintrustOkHttpClient.fromEnv(); ``` @@ -92,7 +92,7 @@ import com.braintrustdata.api.client.BraintrustClient; import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient; BraintrustClient client = BraintrustOkHttpClient.builder() - // Configures using the `BRAINTRUST_API_KEY` environment variable + // Configures using the `BRAINTRUST_API_KEY` and `BRAINTRUST_BASE_URL` environment variables .fromEnv() .apiKey("My API Key") .build(); @@ -100,9 +100,10 @@ BraintrustClient client = BraintrustOkHttpClient.builder() See this table for the available options: -| Setter | Environment variable | Required | Default value | -| -------- | -------------------- | -------- | ------------- | -| `apiKey` | `BRAINTRUST_API_KEY` | false | - | +| Setter | Environment variable | Required | Default value | +| --------- | --------------------- | -------- | ------------------------------ | +| `apiKey` | `BRAINTRUST_API_KEY` | false | - | +| `baseUrl` | `BRAINTRUST_BASE_URL` | true | `"https://api.braintrust.dev"` | > [!TIP] > Don't create more than one client in the same application. Each client has a connection pool and @@ -133,7 +134,7 @@ import com.braintrustdata.api.models.Project; import com.braintrustdata.api.models.ProjectCreateParams; import java.util.concurrent.CompletableFuture; -// Configures using the `BRAINTRUST_API_KEY` environment variable +// Configures using the `BRAINTRUST_API_KEY` and `BRAINTRUST_BASE_URL` environment variables BraintrustClient client = BraintrustOkHttpClient.fromEnv(); ProjectCreateParams params = ProjectCreateParams.builder() @@ -151,7 +152,7 @@ import com.braintrustdata.api.models.Project; import com.braintrustdata.api.models.ProjectCreateParams; import java.util.concurrent.CompletableFuture; -// Configures using the `BRAINTRUST_API_KEY` environment variable +// Configures using the `BRAINTRUST_API_KEY` and `BRAINTRUST_BASE_URL` environment variables BraintrustClientAsync client = BraintrustOkHttpClientAsync.fromEnv(); ProjectCreateParams params = ProjectCreateParams.builder() diff --git a/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClient.kt b/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClient.kt index f94c4c36..aa4f40a4 100755 --- a/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClient.kt +++ b/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClient.kt @@ -29,14 +29,10 @@ class BraintrustOkHttpClient private constructor() { class Builder internal constructor() { private var clientOptions: ClientOptions.Builder = ClientOptions.builder() - private var baseUrl: String = ClientOptions.PRODUCTION_URL private var timeout: Timeout = Timeout.default() private var proxy: Proxy? = null - fun baseUrl(baseUrl: String) = apply { - clientOptions.baseUrl(baseUrl) - this.baseUrl = baseUrl - } + fun baseUrl(baseUrl: String) = apply { clientOptions.baseUrl(baseUrl) } /** * Whether to throw an exception if any of the Jackson versions detected at runtime are @@ -172,7 +168,7 @@ class BraintrustOkHttpClient private constructor() { clientOptions .httpClient( OkHttpClient.builder() - .baseUrl(baseUrl) + .baseUrl(clientOptions.baseUrl()) .timeout(timeout) .proxy(proxy) .build() diff --git a/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClientAsync.kt b/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClientAsync.kt index 861216ed..c0d37976 100755 --- a/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClientAsync.kt +++ b/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClientAsync.kt @@ -31,14 +31,10 @@ class BraintrustOkHttpClientAsync private constructor() { class Builder internal constructor() { private var clientOptions: ClientOptions.Builder = ClientOptions.builder() - private var baseUrl: String = ClientOptions.PRODUCTION_URL private var timeout: Timeout = Timeout.default() private var proxy: Proxy? = null - fun baseUrl(baseUrl: String) = apply { - clientOptions.baseUrl(baseUrl) - this.baseUrl = baseUrl - } + fun baseUrl(baseUrl: String) = apply { clientOptions.baseUrl(baseUrl) } /** * Whether to throw an exception if any of the Jackson versions detected at runtime are @@ -174,7 +170,7 @@ class BraintrustOkHttpClientAsync private constructor() { clientOptions .httpClient( OkHttpClient.builder() - .baseUrl(baseUrl) + .baseUrl(clientOptions.baseUrl()) .timeout(timeout) .proxy(proxy) .build() diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ClientOptions.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ClientOptions.kt index 269345b4..9841ea6e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ClientOptions.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ClientOptions.kt @@ -190,7 +190,12 @@ private constructor( fun removeAllQueryParams(keys: Set) = apply { queryParams.removeAll(keys) } - fun fromEnv() = apply { System.getenv("BRAINTRUST_API_KEY")?.let { apiKey(it) } } + fun baseUrl(): String = baseUrl + + fun fromEnv() = apply { + System.getenv("BRAINTRUST_BASE_URL")?.let { baseUrl(it) } + System.getenv("BRAINTRUST_API_KEY")?.let { apiKey(it) } + } /** * Returns an immutable instance of [ClientOptions]. From 6e596e46185da32341ce8d186a96336f26b2cd56 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 10 Apr 2025 03:40:27 +0000 Subject: [PATCH 31/42] chore(internal): expand CI branch coverage --- .github/workflows/ci.yml | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 94046873..5a6ae118 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,18 +1,18 @@ name: CI on: push: - branches: - - main - pull_request: - branches: - - main - - next + branches-ignore: + - 'generated' + - 'codegen/**' + - 'integrated/**' + - 'preview-head/**' + - 'preview-base/**' + - 'preview/**' jobs: lint: name: lint runs-on: ubuntu-latest - steps: - uses: actions/checkout@v4 @@ -34,7 +34,6 @@ jobs: test: name: test runs-on: ubuntu-latest - steps: - uses: actions/checkout@v4 From a2f69b5a6126c7c8ca17030bea1c0f660183f77f Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 10 Apr 2025 04:12:46 +0000 Subject: [PATCH 32/42] fix(client): bump to better jackson version --- braintrust-java-core/build.gradle.kts | 12 ++++++------ .../main/kotlin/com/braintrustdata/api/core/Check.kt | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/braintrust-java-core/build.gradle.kts b/braintrust-java-core/build.gradle.kts index 839637a1..0e09ef31 100755 --- a/braintrust-java-core/build.gradle.kts +++ b/braintrust-java-core/build.gradle.kts @@ -17,14 +17,14 @@ configurations.all { } dependencies { - api("com.fasterxml.jackson.core:jackson-core:2.18.1") - api("com.fasterxml.jackson.core:jackson-databind:2.18.1") + api("com.fasterxml.jackson.core:jackson-core:2.18.2") + api("com.fasterxml.jackson.core:jackson-databind:2.18.2") api("com.google.errorprone:error_prone_annotations:2.33.0") - implementation("com.fasterxml.jackson.core:jackson-annotations:2.18.1") - implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.18.1") - implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.18.1") - implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.18.1") + implementation("com.fasterxml.jackson.core:jackson-annotations:2.18.2") + implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.18.2") + implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.18.2") + implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.18.2") implementation("org.apache.httpcomponents.core5:httpcore5:5.2.4") implementation("org.apache.httpcomponents.client5:httpclient5:5.3.1") diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Check.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Check.kt index 40e95a5a..dc20c15d 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Check.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Check.kt @@ -47,6 +47,7 @@ internal fun checkMaxLength(name: String, value: String, maxLength: Int): String internal fun checkJacksonVersionCompatibility() { val incompatibleJacksonVersions = RUNTIME_JACKSON_VERSIONS.mapNotNull { + val badVersionReason = BAD_JACKSON_VERSIONS[it.toString()] when { it.majorVersion != MINIMUM_JACKSON_VERSION.majorVersion -> it to "incompatible major version" @@ -55,6 +56,7 @@ internal fun checkJacksonVersionCompatibility() { it.minorVersion == MINIMUM_JACKSON_VERSION.minorVersion && it.patchLevel < MINIMUM_JACKSON_VERSION.patchLevel -> it to "patch version too low" + badVersionReason != null -> it to badVersionReason else -> null } } @@ -77,6 +79,8 @@ Double-check that you are depending on compatible Jackson versions. } private val MINIMUM_JACKSON_VERSION: Version = VersionUtil.parseVersion("2.13.4", null, null) +private val BAD_JACKSON_VERSIONS: Map = + mapOf("2.18.1" to "due to https://github.com/FasterXML/jackson-databind/issues/4639") private val RUNTIME_JACKSON_VERSIONS: List = listOf( com.fasterxml.jackson.core.json.PackageVersion.VERSION, From 445e30ebac1dd50e5cfc22aaf1ef9927fc13796f Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 10 Apr 2025 04:31:40 +0000 Subject: [PATCH 33/42] refactor(client): deduplicate page response classes feat(client): make pagination robust to missing data docs: add comments for page methods --- .../braintrustdata/api/models/AclListPage.kt | 133 +----- .../api/models/AclListPageAsync.kt | 133 +----- .../api/models/AclListPageResponse.kt | 192 +++++++++ .../api/models/AiSecretListPage.kt | 139 +----- .../api/models/AiSecretListPageAsync.kt | 136 +----- .../api/models/AiSecretListPageResponse.kt | 194 +++++++++ .../api/models/ApiKeyListPage.kt | 139 +----- .../api/models/ApiKeyListPageAsync.kt | 139 +----- .../api/models/ApiKeyListPageResponse.kt | 192 +++++++++ .../api/models/DatasetListPage.kt | 139 +----- .../api/models/DatasetListPageAsync.kt | 134 +----- .../api/models/DatasetListPageResponse.kt | 194 +++++++++ .../api/models/ExperimentListPage.kt | 134 +----- .../api/models/ExperimentListPageAsync.kt | 136 +----- .../api/models/ExperimentListPageResponse.kt | 194 +++++++++ .../api/models/FunctionListPage.kt | 139 +----- .../api/models/FunctionListPageAsync.kt | 136 +----- .../api/models/FunctionListPageResponse.kt | 194 +++++++++ .../api/models/GroupListPage.kt | 139 +----- .../api/models/GroupListPageAsync.kt | 139 +----- .../api/models/GroupListPageResponse.kt | 192 +++++++++ .../api/models/OrganizationListPage.kt | 134 +----- .../api/models/OrganizationListPageAsync.kt | 137 +----- .../models/OrganizationListPageResponse.kt | 194 +++++++++ .../api/models/ProjectListPage.kt | 139 +----- .../api/models/ProjectListPageAsync.kt | 134 +----- .../api/models/ProjectListPageResponse.kt | 194 +++++++++ .../api/models/ProjectScoreListPage.kt | 134 +----- .../api/models/ProjectScoreListPageAsync.kt | 137 +----- .../models/ProjectScoreListPageResponse.kt | 194 +++++++++ .../api/models/ProjectTagListPage.kt | 134 +----- .../api/models/ProjectTagListPageAsync.kt | 136 +----- .../api/models/ProjectTagListPageResponse.kt | 194 +++++++++ .../api/models/PromptListPage.kt | 139 +----- .../api/models/PromptListPageAsync.kt | 139 +----- .../api/models/PromptListPageResponse.kt | 192 +++++++++ .../braintrustdata/api/models/RoleListPage.kt | 134 +----- .../api/models/RoleListPageAsync.kt | 139 +----- .../api/models/RoleListPageResponse.kt | 192 +++++++++ .../api/models/SpanIframeListPage.kt | 134 +----- .../api/models/SpanIframeListPageAsync.kt | 136 +----- .../api/models/SpanIframeListPageResponse.kt | 194 +++++++++ .../braintrustdata/api/models/UserListPage.kt | 134 +----- .../api/models/UserListPageAsync.kt | 139 +----- .../api/models/UserListPageResponse.kt | 192 +++++++++ .../braintrustdata/api/models/ViewListPage.kt | 134 +----- .../api/models/ViewListPageAsync.kt | 139 +----- .../api/models/ViewListPageResponse.kt | 192 +++++++++ .../api/services/async/AclServiceAsyncImpl.kt | 5 +- .../async/AiSecretServiceAsyncImpl.kt | 5 +- .../services/async/ApiKeyServiceAsyncImpl.kt | 5 +- .../services/async/DatasetServiceAsyncImpl.kt | 5 +- .../async/ExperimentServiceAsyncImpl.kt | 5 +- .../async/FunctionServiceAsyncImpl.kt | 5 +- .../services/async/GroupServiceAsyncImpl.kt | 5 +- .../async/OrganizationServiceAsyncImpl.kt | 5 +- .../async/ProjectScoreServiceAsyncImpl.kt | 5 +- .../services/async/ProjectServiceAsyncImpl.kt | 5 +- .../async/ProjectTagServiceAsyncImpl.kt | 5 +- .../services/async/PromptServiceAsyncImpl.kt | 5 +- .../services/async/RoleServiceAsyncImpl.kt | 5 +- .../async/SpanIframeServiceAsyncImpl.kt | 5 +- .../services/async/UserServiceAsyncImpl.kt | 5 +- .../services/async/ViewServiceAsyncImpl.kt | 5 +- .../api/services/blocking/AclServiceImpl.kt | 5 +- .../services/blocking/AiSecretServiceImpl.kt | 5 +- .../services/blocking/ApiKeyServiceImpl.kt | 5 +- .../services/blocking/DatasetServiceImpl.kt | 5 +- .../blocking/ExperimentServiceImpl.kt | 5 +- .../services/blocking/FunctionServiceImpl.kt | 5 +- .../api/services/blocking/GroupServiceImpl.kt | 5 +- .../blocking/OrganizationServiceImpl.kt | 5 +- .../blocking/ProjectScoreServiceImpl.kt | 5 +- .../services/blocking/ProjectServiceImpl.kt | 5 +- .../blocking/ProjectTagServiceImpl.kt | 5 +- .../services/blocking/PromptServiceImpl.kt | 5 +- .../api/services/blocking/RoleServiceImpl.kt | 5 +- .../blocking/SpanIframeServiceImpl.kt | 5 +- .../api/services/blocking/UserServiceImpl.kt | 5 +- .../api/services/blocking/ViewServiceImpl.kt | 5 +- .../api/models/AclListPageResponseTest.kt | 79 ++++ .../models/AiSecretListPageResponseTest.kt | 86 ++++ .../api/models/ApiKeyListPageResponseTest.kt | 67 +++ .../api/models/DatasetListPageResponseTest.kt | 86 ++++ .../models/ExperimentListPageResponseTest.kt | 140 ++++++ .../models/FunctionListPageResponseTest.kt | 402 ++++++++++++++++++ .../api/models/GroupListPageResponseTest.kt | 76 ++++ .../OrganizationListPageResponseTest.kt | 70 +++ .../api/models/ProjectListPageResponseTest.kt | 109 +++++ .../ProjectScoreListPageResponseTest.kt | 143 +++++++ .../models/ProjectTagListPageResponseTest.kt | 70 +++ .../api/models/PromptListPageResponseTest.kt | 348 +++++++++++++++ .../api/models/RoleListPageResponseTest.kt | 91 ++++ .../models/SpanIframeListPageResponseTest.kt | 76 ++++ .../api/models/UserListPageResponseTest.kt | 67 +++ .../api/models/ViewListPageResponseTest.kt | 164 +++++++ 96 files changed, 5918 insertions(+), 3773 deletions(-) create mode 100644 braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageResponse.kt create mode 100644 braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageResponse.kt create mode 100644 braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageResponse.kt create mode 100644 braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageResponse.kt create mode 100644 braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageResponse.kt create mode 100644 braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageResponse.kt create mode 100644 braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageResponse.kt create mode 100644 braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageResponse.kt create mode 100644 braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageResponse.kt create mode 100644 braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageResponse.kt create mode 100644 braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageResponse.kt create mode 100644 braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageResponse.kt create mode 100644 braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageResponse.kt create mode 100644 braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageResponse.kt create mode 100644 braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageResponse.kt create mode 100644 braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageResponse.kt create mode 100644 braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclListPageResponseTest.kt create mode 100644 braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretListPageResponseTest.kt create mode 100644 braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ApiKeyListPageResponseTest.kt create mode 100644 braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetListPageResponseTest.kt create mode 100644 braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentListPageResponseTest.kt create mode 100644 braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionListPageResponseTest.kt create mode 100644 braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupListPageResponseTest.kt create mode 100644 braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationListPageResponseTest.kt create mode 100644 braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectListPageResponseTest.kt create mode 100644 braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreListPageResponseTest.kt create mode 100644 braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagListPageResponseTest.kt create mode 100644 braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptListPageResponseTest.kt create mode 100644 braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleListPageResponseTest.kt create mode 100644 braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeListPageResponseTest.kt create mode 100644 braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/UserListPageResponseTest.kt create mode 100644 braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewListPageResponseTest.kt diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt index 58416bbb..08254621 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.AclService -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -27,12 +17,18 @@ class AclListPage private constructor( private val aclsService: AclService, private val params: AclListParams, - private val response: Response, + private val response: AclListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): AclListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [AclListPageResponse], but gracefully handles missing data. + * + * @see [AclListPageResponse.objects] + */ + fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -47,20 +43,20 @@ private constructor( override fun toString() = "AclListPage{aclsService=$aclsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): Optional { @@ -72,103 +68,10 @@ private constructor( companion object { @JvmStatic - fun of(aclsService: AclService, params: AclListParams, response: Response) = + fun of(aclsService: AclService, params: AclListParams, response: AclListPageResponse) = AclListPage(aclsService, params, response) } - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** Returns a mutable builder for constructing an instance of [AclListPage]. */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } - } - class AutoPager(private val firstPage: AclListPage) : Iterable { override fun iterator(): Iterator = iterator { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt index e876813a..e2491ba1 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.AclServiceAsync -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -28,12 +18,18 @@ class AclListPageAsync private constructor( private val aclsService: AclServiceAsync, private val params: AclListParams, - private val response: Response, + private val response: AclListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): AclListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [AclListPageResponse], but gracefully handles missing data. + * + * @see [AclListPageResponse.objects] + */ + fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -48,20 +44,20 @@ private constructor( override fun toString() = "AclListPageAsync{aclsService=$aclsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): CompletableFuture> { @@ -75,103 +71,10 @@ private constructor( companion object { @JvmStatic - fun of(aclsService: AclServiceAsync, params: AclListParams, response: Response) = + fun of(aclsService: AclServiceAsync, params: AclListParams, response: AclListPageResponse) = AclListPageAsync(aclsService, params, response) } - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** Returns a mutable builder for constructing an instance of [AclListPageAsync]. */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } - } - class AutoPager(private val firstPage: AclListPageAsync) { fun forEach(action: Predicate, executor: Executor): CompletableFuture { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageResponse.kt new file mode 100644 index 00000000..63b51fd2 --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageResponse.kt @@ -0,0 +1,192 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.ExcludeMissing +import com.braintrustdata.api.core.JsonField +import com.braintrustdata.api.core.JsonMissing +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.checkKnown +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.toImmutable +import com.braintrustdata.api.errors.BraintrustInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class AclListPageResponse +private constructor( + private val objects: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("objects") @ExcludeMissing objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + + /** + * A list of acl objects + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun objects(): List = objects.getRequired("objects") + + /** + * Returns the raw JSON value of [objects]. + * + * Unlike [objects], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("objects") @ExcludeMissing fun _objects(): JsonField> = objects + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [AclListPageResponse]. + * + * The following fields are required: + * ```java + * .objects() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AclListPageResponse]. */ + class Builder internal constructor() { + + private var objects: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(aclListPageResponse: AclListPageResponse) = apply { + objects = aclListPageResponse.objects.map { it.toMutableList() } + additionalProperties = aclListPageResponse.additionalProperties.toMutableMap() + } + + /** A list of acl objects */ + fun objects(objects: List) = objects(JsonField.of(objects)) + + /** + * Sets [Builder.objects] to an arbitrary JSON value. + * + * You should usually call [Builder.objects] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun objects(objects: JsonField>) = apply { + this.objects = objects.map { it.toMutableList() } + } + + /** + * Adds a single [Acl] to [objects]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addObject(object_: Acl) = apply { + objects = + (objects ?: JsonField.of(mutableListOf())).also { + checkKnown("objects", it).add(object_) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [AclListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .objects() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AclListPageResponse = + AclListPageResponse( + checkRequired("objects", objects).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): AclListPageResponse = apply { + if (validated) { + return@apply + } + + objects().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (objects.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is AclListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AclListPageResponse{objects=$objects, additionalProperties=$additionalProperties}" +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt index 51743d35..620e441e 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.AiSecretService -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -27,12 +17,19 @@ class AiSecretListPage private constructor( private val aiSecretsService: AiSecretService, private val params: AiSecretListParams, - private val response: Response, + private val response: AiSecretListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): AiSecretListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [AiSecretListPageResponse], but gracefully handles missing data. + * + * @see [AiSecretListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -47,20 +44,20 @@ private constructor( override fun toString() = "AiSecretListPage{aiSecretsService=$aiSecretsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): Optional { @@ -72,101 +69,11 @@ private constructor( companion object { @JvmStatic - fun of(aiSecretsService: AiSecretService, params: AiSecretListParams, response: Response) = - AiSecretListPage(aiSecretsService, params, response) - } - - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** Returns a mutable builder for constructing an instance of [AiSecretListPage]. */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } + fun of( + aiSecretsService: AiSecretService, + params: AiSecretListParams, + response: AiSecretListPageResponse, + ) = AiSecretListPage(aiSecretsService, params, response) } class AutoPager(private val firstPage: AiSecretListPage) : Iterable { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt index a156ff87..a81fec2f 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.AiSecretServiceAsync -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -28,12 +18,19 @@ class AiSecretListPageAsync private constructor( private val aiSecretsService: AiSecretServiceAsync, private val params: AiSecretListParams, - private val response: Response, + private val response: AiSecretListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): AiSecretListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [AiSecretListPageResponse], but gracefully handles missing data. + * + * @see [AiSecretListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -48,20 +45,20 @@ private constructor( override fun toString() = "AiSecretListPageAsync{aiSecretsService=$aiSecretsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): CompletableFuture> { @@ -78,105 +75,10 @@ private constructor( fun of( aiSecretsService: AiSecretServiceAsync, params: AiSecretListParams, - response: Response, + response: AiSecretListPageResponse, ) = AiSecretListPageAsync(aiSecretsService, params, response) } - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [AiSecretListPageAsync]. - */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } - } - class AutoPager(private val firstPage: AiSecretListPageAsync) { fun forEach(action: Predicate, executor: Executor): CompletableFuture { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageResponse.kt new file mode 100644 index 00000000..57a8dde7 --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageResponse.kt @@ -0,0 +1,194 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.ExcludeMissing +import com.braintrustdata.api.core.JsonField +import com.braintrustdata.api.core.JsonMissing +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.checkKnown +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.toImmutable +import com.braintrustdata.api.errors.BraintrustInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class AiSecretListPageResponse +private constructor( + private val objects: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("objects") + @ExcludeMissing + objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + + /** + * A list of ai_secret objects + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun objects(): List = objects.getRequired("objects") + + /** + * Returns the raw JSON value of [objects]. + * + * Unlike [objects], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("objects") @ExcludeMissing fun _objects(): JsonField> = objects + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [AiSecretListPageResponse]. + * + * The following fields are required: + * ```java + * .objects() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AiSecretListPageResponse]. */ + class Builder internal constructor() { + + private var objects: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(aiSecretListPageResponse: AiSecretListPageResponse) = apply { + objects = aiSecretListPageResponse.objects.map { it.toMutableList() } + additionalProperties = aiSecretListPageResponse.additionalProperties.toMutableMap() + } + + /** A list of ai_secret objects */ + fun objects(objects: List) = objects(JsonField.of(objects)) + + /** + * Sets [Builder.objects] to an arbitrary JSON value. + * + * You should usually call [Builder.objects] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun objects(objects: JsonField>) = apply { + this.objects = objects.map { it.toMutableList() } + } + + /** + * Adds a single [AISecret] to [objects]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addObject(object_: AISecret) = apply { + objects = + (objects ?: JsonField.of(mutableListOf())).also { + checkKnown("objects", it).add(object_) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [AiSecretListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .objects() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AiSecretListPageResponse = + AiSecretListPageResponse( + checkRequired("objects", objects).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): AiSecretListPageResponse = apply { + if (validated) { + return@apply + } + + objects().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (objects.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is AiSecretListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AiSecretListPageResponse{objects=$objects, additionalProperties=$additionalProperties}" +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt index 7405bca0..9947a7ff 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.ApiKeyService -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -27,12 +17,19 @@ class ApiKeyListPage private constructor( private val apiKeysService: ApiKeyService, private val params: ApiKeyListParams, - private val response: Response, + private val response: ApiKeyListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): ApiKeyListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [ApiKeyListPageResponse], but gracefully handles missing data. + * + * @see [ApiKeyListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -47,20 +44,20 @@ private constructor( override fun toString() = "ApiKeyListPage{apiKeysService=$apiKeysService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): Optional { @@ -72,101 +69,11 @@ private constructor( companion object { @JvmStatic - fun of(apiKeysService: ApiKeyService, params: ApiKeyListParams, response: Response) = - ApiKeyListPage(apiKeysService, params, response) - } - - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** Returns a mutable builder for constructing an instance of [ApiKeyListPage]. */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } + fun of( + apiKeysService: ApiKeyService, + params: ApiKeyListParams, + response: ApiKeyListPageResponse, + ) = ApiKeyListPage(apiKeysService, params, response) } class AutoPager(private val firstPage: ApiKeyListPage) : Iterable { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt index 9c4ee966..4b756792 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.ApiKeyServiceAsync -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -28,12 +18,19 @@ class ApiKeyListPageAsync private constructor( private val apiKeysService: ApiKeyServiceAsync, private val params: ApiKeyListParams, - private val response: Response, + private val response: ApiKeyListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): ApiKeyListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [ApiKeyListPageResponse], but gracefully handles missing data. + * + * @see [ApiKeyListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -48,20 +45,20 @@ private constructor( override fun toString() = "ApiKeyListPageAsync{apiKeysService=$apiKeysService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): CompletableFuture> { @@ -75,101 +72,11 @@ private constructor( companion object { @JvmStatic - fun of(apiKeysService: ApiKeyServiceAsync, params: ApiKeyListParams, response: Response) = - ApiKeyListPageAsync(apiKeysService, params, response) - } - - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** Returns a mutable builder for constructing an instance of [ApiKeyListPageAsync]. */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } + fun of( + apiKeysService: ApiKeyServiceAsync, + params: ApiKeyListParams, + response: ApiKeyListPageResponse, + ) = ApiKeyListPageAsync(apiKeysService, params, response) } class AutoPager(private val firstPage: ApiKeyListPageAsync) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageResponse.kt new file mode 100644 index 00000000..9c42308a --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageResponse.kt @@ -0,0 +1,192 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.ExcludeMissing +import com.braintrustdata.api.core.JsonField +import com.braintrustdata.api.core.JsonMissing +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.checkKnown +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.toImmutable +import com.braintrustdata.api.errors.BraintrustInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class ApiKeyListPageResponse +private constructor( + private val objects: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("objects") @ExcludeMissing objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + + /** + * A list of api_key objects + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun objects(): List = objects.getRequired("objects") + + /** + * Returns the raw JSON value of [objects]. + * + * Unlike [objects], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("objects") @ExcludeMissing fun _objects(): JsonField> = objects + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ApiKeyListPageResponse]. + * + * The following fields are required: + * ```java + * .objects() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ApiKeyListPageResponse]. */ + class Builder internal constructor() { + + private var objects: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(apiKeyListPageResponse: ApiKeyListPageResponse) = apply { + objects = apiKeyListPageResponse.objects.map { it.toMutableList() } + additionalProperties = apiKeyListPageResponse.additionalProperties.toMutableMap() + } + + /** A list of api_key objects */ + fun objects(objects: List) = objects(JsonField.of(objects)) + + /** + * Sets [Builder.objects] to an arbitrary JSON value. + * + * You should usually call [Builder.objects] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun objects(objects: JsonField>) = apply { + this.objects = objects.map { it.toMutableList() } + } + + /** + * Adds a single [ApiKey] to [objects]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addObject(object_: ApiKey) = apply { + objects = + (objects ?: JsonField.of(mutableListOf())).also { + checkKnown("objects", it).add(object_) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [ApiKeyListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .objects() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ApiKeyListPageResponse = + ApiKeyListPageResponse( + checkRequired("objects", objects).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ApiKeyListPageResponse = apply { + if (validated) { + return@apply + } + + objects().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (objects.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ApiKeyListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ApiKeyListPageResponse{objects=$objects, additionalProperties=$additionalProperties}" +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt index 3a8206b0..a1fb69d0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.DatasetService -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -27,12 +17,19 @@ class DatasetListPage private constructor( private val datasetsService: DatasetService, private val params: DatasetListParams, - private val response: Response, + private val response: DatasetListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): DatasetListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [DatasetListPageResponse], but gracefully handles missing data. + * + * @see [DatasetListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -47,20 +44,20 @@ private constructor( override fun toString() = "DatasetListPage{datasetsService=$datasetsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): Optional { @@ -72,101 +69,11 @@ private constructor( companion object { @JvmStatic - fun of(datasetsService: DatasetService, params: DatasetListParams, response: Response) = - DatasetListPage(datasetsService, params, response) - } - - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** Returns a mutable builder for constructing an instance of [DatasetListPage]. */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } + fun of( + datasetsService: DatasetService, + params: DatasetListParams, + response: DatasetListPageResponse, + ) = DatasetListPage(datasetsService, params, response) } class AutoPager(private val firstPage: DatasetListPage) : Iterable { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt index f8a02f19..85a26a5f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.DatasetServiceAsync -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -28,12 +18,19 @@ class DatasetListPageAsync private constructor( private val datasetsService: DatasetServiceAsync, private val params: DatasetListParams, - private val response: Response, + private val response: DatasetListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): DatasetListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [DatasetListPageResponse], but gracefully handles missing data. + * + * @see [DatasetListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -48,20 +45,20 @@ private constructor( override fun toString() = "DatasetListPageAsync{datasetsService=$datasetsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): CompletableFuture> { @@ -78,103 +75,10 @@ private constructor( fun of( datasetsService: DatasetServiceAsync, params: DatasetListParams, - response: Response, + response: DatasetListPageResponse, ) = DatasetListPageAsync(datasetsService, params, response) } - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** Returns a mutable builder for constructing an instance of [DatasetListPageAsync]. */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } - } - class AutoPager(private val firstPage: DatasetListPageAsync) { fun forEach(action: Predicate, executor: Executor): CompletableFuture { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageResponse.kt new file mode 100644 index 00000000..303e25f0 --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageResponse.kt @@ -0,0 +1,194 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.ExcludeMissing +import com.braintrustdata.api.core.JsonField +import com.braintrustdata.api.core.JsonMissing +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.checkKnown +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.toImmutable +import com.braintrustdata.api.errors.BraintrustInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class DatasetListPageResponse +private constructor( + private val objects: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("objects") + @ExcludeMissing + objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + + /** + * A list of dataset objects + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun objects(): List = objects.getRequired("objects") + + /** + * Returns the raw JSON value of [objects]. + * + * Unlike [objects], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("objects") @ExcludeMissing fun _objects(): JsonField> = objects + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [DatasetListPageResponse]. + * + * The following fields are required: + * ```java + * .objects() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [DatasetListPageResponse]. */ + class Builder internal constructor() { + + private var objects: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(datasetListPageResponse: DatasetListPageResponse) = apply { + objects = datasetListPageResponse.objects.map { it.toMutableList() } + additionalProperties = datasetListPageResponse.additionalProperties.toMutableMap() + } + + /** A list of dataset objects */ + fun objects(objects: List) = objects(JsonField.of(objects)) + + /** + * Sets [Builder.objects] to an arbitrary JSON value. + * + * You should usually call [Builder.objects] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun objects(objects: JsonField>) = apply { + this.objects = objects.map { it.toMutableList() } + } + + /** + * Adds a single [Dataset] to [objects]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addObject(object_: Dataset) = apply { + objects = + (objects ?: JsonField.of(mutableListOf())).also { + checkKnown("objects", it).add(object_) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [DatasetListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .objects() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): DatasetListPageResponse = + DatasetListPageResponse( + checkRequired("objects", objects).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): DatasetListPageResponse = apply { + if (validated) { + return@apply + } + + objects().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (objects.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is DatasetListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "DatasetListPageResponse{objects=$objects, additionalProperties=$additionalProperties}" +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt index c6415ba6..d31124c0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.ExperimentService -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -27,12 +17,19 @@ class ExperimentListPage private constructor( private val experimentsService: ExperimentService, private val params: ExperimentListParams, - private val response: Response, + private val response: ExperimentListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): ExperimentListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [ExperimentListPageResponse], but gracefully handles missing data. + * + * @see [ExperimentListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -47,20 +44,20 @@ private constructor( override fun toString() = "ExperimentListPage{experimentsService=$experimentsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): Optional { @@ -75,103 +72,10 @@ private constructor( fun of( experimentsService: ExperimentService, params: ExperimentListParams, - response: Response, + response: ExperimentListPageResponse, ) = ExperimentListPage(experimentsService, params, response) } - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** Returns a mutable builder for constructing an instance of [ExperimentListPage]. */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } - } - class AutoPager(private val firstPage: ExperimentListPage) : Iterable { override fun iterator(): Iterator = iterator { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt index 56589a1b..72766718 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.ExperimentServiceAsync -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -28,12 +18,19 @@ class ExperimentListPageAsync private constructor( private val experimentsService: ExperimentServiceAsync, private val params: ExperimentListParams, - private val response: Response, + private val response: ExperimentListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): ExperimentListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [ExperimentListPageResponse], but gracefully handles missing data. + * + * @see [ExperimentListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -48,20 +45,20 @@ private constructor( override fun toString() = "ExperimentListPageAsync{experimentsService=$experimentsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): CompletableFuture> { @@ -78,105 +75,10 @@ private constructor( fun of( experimentsService: ExperimentServiceAsync, params: ExperimentListParams, - response: Response, + response: ExperimentListPageResponse, ) = ExperimentListPageAsync(experimentsService, params, response) } - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [ExperimentListPageAsync]. - */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } - } - class AutoPager(private val firstPage: ExperimentListPageAsync) { fun forEach(action: Predicate, executor: Executor): CompletableFuture { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageResponse.kt new file mode 100644 index 00000000..ae4bfd1c --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageResponse.kt @@ -0,0 +1,194 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.ExcludeMissing +import com.braintrustdata.api.core.JsonField +import com.braintrustdata.api.core.JsonMissing +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.checkKnown +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.toImmutable +import com.braintrustdata.api.errors.BraintrustInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class ExperimentListPageResponse +private constructor( + private val objects: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("objects") + @ExcludeMissing + objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + + /** + * A list of experiment objects + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun objects(): List = objects.getRequired("objects") + + /** + * Returns the raw JSON value of [objects]. + * + * Unlike [objects], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("objects") @ExcludeMissing fun _objects(): JsonField> = objects + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ExperimentListPageResponse]. + * + * The following fields are required: + * ```java + * .objects() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ExperimentListPageResponse]. */ + class Builder internal constructor() { + + private var objects: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(experimentListPageResponse: ExperimentListPageResponse) = apply { + objects = experimentListPageResponse.objects.map { it.toMutableList() } + additionalProperties = experimentListPageResponse.additionalProperties.toMutableMap() + } + + /** A list of experiment objects */ + fun objects(objects: List) = objects(JsonField.of(objects)) + + /** + * Sets [Builder.objects] to an arbitrary JSON value. + * + * You should usually call [Builder.objects] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun objects(objects: JsonField>) = apply { + this.objects = objects.map { it.toMutableList() } + } + + /** + * Adds a single [Experiment] to [objects]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addObject(object_: Experiment) = apply { + objects = + (objects ?: JsonField.of(mutableListOf())).also { + checkKnown("objects", it).add(object_) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [ExperimentListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .objects() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ExperimentListPageResponse = + ExperimentListPageResponse( + checkRequired("objects", objects).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ExperimentListPageResponse = apply { + if (validated) { + return@apply + } + + objects().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (objects.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ExperimentListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ExperimentListPageResponse{objects=$objects, additionalProperties=$additionalProperties}" +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPage.kt index 46b65193..785f5713 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPage.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.FunctionService -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -27,12 +17,19 @@ class FunctionListPage private constructor( private val functionsService: FunctionService, private val params: FunctionListParams, - private val response: Response, + private val response: FunctionListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): FunctionListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [FunctionListPageResponse], but gracefully handles missing data. + * + * @see [FunctionListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -47,20 +44,20 @@ private constructor( override fun toString() = "FunctionListPage{functionsService=$functionsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): Optional { @@ -72,101 +69,11 @@ private constructor( companion object { @JvmStatic - fun of(functionsService: FunctionService, params: FunctionListParams, response: Response) = - FunctionListPage(functionsService, params, response) - } - - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** Returns a mutable builder for constructing an instance of [FunctionListPage]. */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } + fun of( + functionsService: FunctionService, + params: FunctionListParams, + response: FunctionListPageResponse, + ) = FunctionListPage(functionsService, params, response) } class AutoPager(private val firstPage: FunctionListPage) : Iterable { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageAsync.kt index df33ddc9..5f2f641f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageAsync.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.FunctionServiceAsync -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -28,12 +18,19 @@ class FunctionListPageAsync private constructor( private val functionsService: FunctionServiceAsync, private val params: FunctionListParams, - private val response: Response, + private val response: FunctionListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): FunctionListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [FunctionListPageResponse], but gracefully handles missing data. + * + * @see [FunctionListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -48,20 +45,20 @@ private constructor( override fun toString() = "FunctionListPageAsync{functionsService=$functionsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): CompletableFuture> { @@ -78,105 +75,10 @@ private constructor( fun of( functionsService: FunctionServiceAsync, params: FunctionListParams, - response: Response, + response: FunctionListPageResponse, ) = FunctionListPageAsync(functionsService, params, response) } - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [FunctionListPageAsync]. - */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } - } - class AutoPager(private val firstPage: FunctionListPageAsync) { fun forEach(action: Predicate, executor: Executor): CompletableFuture { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageResponse.kt new file mode 100644 index 00000000..09acf2d6 --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageResponse.kt @@ -0,0 +1,194 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.ExcludeMissing +import com.braintrustdata.api.core.JsonField +import com.braintrustdata.api.core.JsonMissing +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.checkKnown +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.toImmutable +import com.braintrustdata.api.errors.BraintrustInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class FunctionListPageResponse +private constructor( + private val objects: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("objects") + @ExcludeMissing + objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + + /** + * A list of function objects + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun objects(): List = objects.getRequired("objects") + + /** + * Returns the raw JSON value of [objects]. + * + * Unlike [objects], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("objects") @ExcludeMissing fun _objects(): JsonField> = objects + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [FunctionListPageResponse]. + * + * The following fields are required: + * ```java + * .objects() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [FunctionListPageResponse]. */ + class Builder internal constructor() { + + private var objects: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(functionListPageResponse: FunctionListPageResponse) = apply { + objects = functionListPageResponse.objects.map { it.toMutableList() } + additionalProperties = functionListPageResponse.additionalProperties.toMutableMap() + } + + /** A list of function objects */ + fun objects(objects: List) = objects(JsonField.of(objects)) + + /** + * Sets [Builder.objects] to an arbitrary JSON value. + * + * You should usually call [Builder.objects] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun objects(objects: JsonField>) = apply { + this.objects = objects.map { it.toMutableList() } + } + + /** + * Adds a single [Function] to [objects]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addObject(object_: Function) = apply { + objects = + (objects ?: JsonField.of(mutableListOf())).also { + checkKnown("objects", it).add(object_) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [FunctionListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .objects() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): FunctionListPageResponse = + FunctionListPageResponse( + checkRequired("objects", objects).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): FunctionListPageResponse = apply { + if (validated) { + return@apply + } + + objects().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (objects.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FunctionListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "FunctionListPageResponse{objects=$objects, additionalProperties=$additionalProperties}" +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt index 29cb7043..440a7ad4 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.GroupService -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -27,12 +17,19 @@ class GroupListPage private constructor( private val groupsService: GroupService, private val params: GroupListParams, - private val response: Response, + private val response: GroupListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): GroupListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [GroupListPageResponse], but gracefully handles missing data. + * + * @see [GroupListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -47,20 +44,20 @@ private constructor( override fun toString() = "GroupListPage{groupsService=$groupsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): Optional { @@ -72,101 +69,11 @@ private constructor( companion object { @JvmStatic - fun of(groupsService: GroupService, params: GroupListParams, response: Response) = - GroupListPage(groupsService, params, response) - } - - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** Returns a mutable builder for constructing an instance of [GroupListPage]. */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } + fun of( + groupsService: GroupService, + params: GroupListParams, + response: GroupListPageResponse, + ) = GroupListPage(groupsService, params, response) } class AutoPager(private val firstPage: GroupListPage) : Iterable { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt index 35febb40..74a130f3 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.GroupServiceAsync -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -28,12 +18,19 @@ class GroupListPageAsync private constructor( private val groupsService: GroupServiceAsync, private val params: GroupListParams, - private val response: Response, + private val response: GroupListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): GroupListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [GroupListPageResponse], but gracefully handles missing data. + * + * @see [GroupListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -48,20 +45,20 @@ private constructor( override fun toString() = "GroupListPageAsync{groupsService=$groupsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): CompletableFuture> { @@ -75,101 +72,11 @@ private constructor( companion object { @JvmStatic - fun of(groupsService: GroupServiceAsync, params: GroupListParams, response: Response) = - GroupListPageAsync(groupsService, params, response) - } - - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** Returns a mutable builder for constructing an instance of [GroupListPageAsync]. */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } + fun of( + groupsService: GroupServiceAsync, + params: GroupListParams, + response: GroupListPageResponse, + ) = GroupListPageAsync(groupsService, params, response) } class AutoPager(private val firstPage: GroupListPageAsync) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageResponse.kt new file mode 100644 index 00000000..dafbd5f2 --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageResponse.kt @@ -0,0 +1,192 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.ExcludeMissing +import com.braintrustdata.api.core.JsonField +import com.braintrustdata.api.core.JsonMissing +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.checkKnown +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.toImmutable +import com.braintrustdata.api.errors.BraintrustInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class GroupListPageResponse +private constructor( + private val objects: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("objects") @ExcludeMissing objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + + /** + * A list of group objects + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun objects(): List = objects.getRequired("objects") + + /** + * Returns the raw JSON value of [objects]. + * + * Unlike [objects], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("objects") @ExcludeMissing fun _objects(): JsonField> = objects + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [GroupListPageResponse]. + * + * The following fields are required: + * ```java + * .objects() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [GroupListPageResponse]. */ + class Builder internal constructor() { + + private var objects: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(groupListPageResponse: GroupListPageResponse) = apply { + objects = groupListPageResponse.objects.map { it.toMutableList() } + additionalProperties = groupListPageResponse.additionalProperties.toMutableMap() + } + + /** A list of group objects */ + fun objects(objects: List) = objects(JsonField.of(objects)) + + /** + * Sets [Builder.objects] to an arbitrary JSON value. + * + * You should usually call [Builder.objects] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun objects(objects: JsonField>) = apply { + this.objects = objects.map { it.toMutableList() } + } + + /** + * Adds a single [Group] to [objects]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addObject(object_: Group) = apply { + objects = + (objects ?: JsonField.of(mutableListOf())).also { + checkKnown("objects", it).add(object_) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [GroupListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .objects() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupListPageResponse = + GroupListPageResponse( + checkRequired("objects", objects).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupListPageResponse = apply { + if (validated) { + return@apply + } + + objects().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (objects.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is GroupListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupListPageResponse{objects=$objects, additionalProperties=$additionalProperties}" +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt index 8bd16fed..28301816 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.OrganizationService -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -27,12 +17,19 @@ class OrganizationListPage private constructor( private val organizationsService: OrganizationService, private val params: OrganizationListParams, - private val response: Response, + private val response: OrganizationListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): OrganizationListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [OrganizationListPageResponse], but gracefully handles missing data. + * + * @see [OrganizationListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -47,20 +44,20 @@ private constructor( override fun toString() = "OrganizationListPage{organizationsService=$organizationsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): Optional { @@ -75,103 +72,10 @@ private constructor( fun of( organizationsService: OrganizationService, params: OrganizationListParams, - response: Response, + response: OrganizationListPageResponse, ) = OrganizationListPage(organizationsService, params, response) } - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** Returns a mutable builder for constructing an instance of [OrganizationListPage]. */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } - } - class AutoPager(private val firstPage: OrganizationListPage) : Iterable { override fun iterator(): Iterator = iterator { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt index 59689415..02e8363c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.OrganizationServiceAsync -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -28,12 +18,19 @@ class OrganizationListPageAsync private constructor( private val organizationsService: OrganizationServiceAsync, private val params: OrganizationListParams, - private val response: Response, + private val response: OrganizationListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): OrganizationListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [OrganizationListPageResponse], but gracefully handles missing data. + * + * @see [OrganizationListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -48,20 +45,20 @@ private constructor( override fun toString() = "OrganizationListPageAsync{organizationsService=$organizationsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): CompletableFuture> { @@ -78,106 +75,10 @@ private constructor( fun of( organizationsService: OrganizationServiceAsync, params: OrganizationListParams, - response: Response, + response: OrganizationListPageResponse, ) = OrganizationListPageAsync(organizationsService, params, response) } - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [OrganizationListPageAsync]. - */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } - } - class AutoPager(private val firstPage: OrganizationListPageAsync) { fun forEach(action: Predicate, executor: Executor): CompletableFuture { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageResponse.kt new file mode 100644 index 00000000..2bd0dfe3 --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageResponse.kt @@ -0,0 +1,194 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.ExcludeMissing +import com.braintrustdata.api.core.JsonField +import com.braintrustdata.api.core.JsonMissing +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.checkKnown +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.toImmutable +import com.braintrustdata.api.errors.BraintrustInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class OrganizationListPageResponse +private constructor( + private val objects: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("objects") + @ExcludeMissing + objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + + /** + * A list of organization objects + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun objects(): List = objects.getRequired("objects") + + /** + * Returns the raw JSON value of [objects]. + * + * Unlike [objects], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("objects") @ExcludeMissing fun _objects(): JsonField> = objects + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [OrganizationListPageResponse]. + * + * The following fields are required: + * ```java + * .objects() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationListPageResponse]. */ + class Builder internal constructor() { + + private var objects: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(organizationListPageResponse: OrganizationListPageResponse) = apply { + objects = organizationListPageResponse.objects.map { it.toMutableList() } + additionalProperties = organizationListPageResponse.additionalProperties.toMutableMap() + } + + /** A list of organization objects */ + fun objects(objects: List) = objects(JsonField.of(objects)) + + /** + * Sets [Builder.objects] to an arbitrary JSON value. + * + * You should usually call [Builder.objects] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun objects(objects: JsonField>) = apply { + this.objects = objects.map { it.toMutableList() } + } + + /** + * Adds a single [Organization] to [objects]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addObject(object_: Organization) = apply { + objects = + (objects ?: JsonField.of(mutableListOf())).also { + checkKnown("objects", it).add(object_) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [OrganizationListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .objects() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationListPageResponse = + OrganizationListPageResponse( + checkRequired("objects", objects).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): OrganizationListPageResponse = apply { + if (validated) { + return@apply + } + + objects().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (objects.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is OrganizationListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OrganizationListPageResponse{objects=$objects, additionalProperties=$additionalProperties}" +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPage.kt index 242b2908..9e74375f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPage.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.ProjectService -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -27,12 +17,19 @@ class ProjectListPage private constructor( private val projectsService: ProjectService, private val params: ProjectListParams, - private val response: Response, + private val response: ProjectListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): ProjectListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [ProjectListPageResponse], but gracefully handles missing data. + * + * @see [ProjectListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -47,20 +44,20 @@ private constructor( override fun toString() = "ProjectListPage{projectsService=$projectsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): Optional { @@ -72,101 +69,11 @@ private constructor( companion object { @JvmStatic - fun of(projectsService: ProjectService, params: ProjectListParams, response: Response) = - ProjectListPage(projectsService, params, response) - } - - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** Returns a mutable builder for constructing an instance of [ProjectListPage]. */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } + fun of( + projectsService: ProjectService, + params: ProjectListParams, + response: ProjectListPageResponse, + ) = ProjectListPage(projectsService, params, response) } class AutoPager(private val firstPage: ProjectListPage) : Iterable { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageAsync.kt index 803d890c..fbb36339 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageAsync.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.ProjectServiceAsync -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -28,12 +18,19 @@ class ProjectListPageAsync private constructor( private val projectsService: ProjectServiceAsync, private val params: ProjectListParams, - private val response: Response, + private val response: ProjectListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): ProjectListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [ProjectListPageResponse], but gracefully handles missing data. + * + * @see [ProjectListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -48,20 +45,20 @@ private constructor( override fun toString() = "ProjectListPageAsync{projectsService=$projectsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): CompletableFuture> { @@ -78,103 +75,10 @@ private constructor( fun of( projectsService: ProjectServiceAsync, params: ProjectListParams, - response: Response, + response: ProjectListPageResponse, ) = ProjectListPageAsync(projectsService, params, response) } - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** Returns a mutable builder for constructing an instance of [ProjectListPageAsync]. */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } - } - class AutoPager(private val firstPage: ProjectListPageAsync) { fun forEach(action: Predicate, executor: Executor): CompletableFuture { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageResponse.kt new file mode 100644 index 00000000..b789cd90 --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageResponse.kt @@ -0,0 +1,194 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.ExcludeMissing +import com.braintrustdata.api.core.JsonField +import com.braintrustdata.api.core.JsonMissing +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.checkKnown +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.toImmutable +import com.braintrustdata.api.errors.BraintrustInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class ProjectListPageResponse +private constructor( + private val objects: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("objects") + @ExcludeMissing + objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + + /** + * A list of project objects + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun objects(): List = objects.getRequired("objects") + + /** + * Returns the raw JSON value of [objects]. + * + * Unlike [objects], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("objects") @ExcludeMissing fun _objects(): JsonField> = objects + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ProjectListPageResponse]. + * + * The following fields are required: + * ```java + * .objects() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProjectListPageResponse]. */ + class Builder internal constructor() { + + private var objects: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(projectListPageResponse: ProjectListPageResponse) = apply { + objects = projectListPageResponse.objects.map { it.toMutableList() } + additionalProperties = projectListPageResponse.additionalProperties.toMutableMap() + } + + /** A list of project objects */ + fun objects(objects: List) = objects(JsonField.of(objects)) + + /** + * Sets [Builder.objects] to an arbitrary JSON value. + * + * You should usually call [Builder.objects] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun objects(objects: JsonField>) = apply { + this.objects = objects.map { it.toMutableList() } + } + + /** + * Adds a single [Project] to [objects]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addObject(object_: Project) = apply { + objects = + (objects ?: JsonField.of(mutableListOf())).also { + checkKnown("objects", it).add(object_) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [ProjectListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .objects() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProjectListPageResponse = + ProjectListPageResponse( + checkRequired("objects", objects).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ProjectListPageResponse = apply { + if (validated) { + return@apply + } + + objects().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (objects.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ProjectListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ProjectListPageResponse{objects=$objects, additionalProperties=$additionalProperties}" +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt index 9ca7e11c..038d6723 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.ProjectScoreService -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -27,12 +17,19 @@ class ProjectScoreListPage private constructor( private val projectScoresService: ProjectScoreService, private val params: ProjectScoreListParams, - private val response: Response, + private val response: ProjectScoreListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): ProjectScoreListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [ProjectScoreListPageResponse], but gracefully handles missing data. + * + * @see [ProjectScoreListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -47,20 +44,20 @@ private constructor( override fun toString() = "ProjectScoreListPage{projectScoresService=$projectScoresService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): Optional { @@ -75,103 +72,10 @@ private constructor( fun of( projectScoresService: ProjectScoreService, params: ProjectScoreListParams, - response: Response, + response: ProjectScoreListPageResponse, ) = ProjectScoreListPage(projectScoresService, params, response) } - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** Returns a mutable builder for constructing an instance of [ProjectScoreListPage]. */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } - } - class AutoPager(private val firstPage: ProjectScoreListPage) : Iterable { override fun iterator(): Iterator = iterator { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt index c6112ce9..98374dc7 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.ProjectScoreServiceAsync -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -28,12 +18,19 @@ class ProjectScoreListPageAsync private constructor( private val projectScoresService: ProjectScoreServiceAsync, private val params: ProjectScoreListParams, - private val response: Response, + private val response: ProjectScoreListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): ProjectScoreListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [ProjectScoreListPageResponse], but gracefully handles missing data. + * + * @see [ProjectScoreListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -48,20 +45,20 @@ private constructor( override fun toString() = "ProjectScoreListPageAsync{projectScoresService=$projectScoresService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): CompletableFuture> { @@ -78,106 +75,10 @@ private constructor( fun of( projectScoresService: ProjectScoreServiceAsync, params: ProjectScoreListParams, - response: Response, + response: ProjectScoreListPageResponse, ) = ProjectScoreListPageAsync(projectScoresService, params, response) } - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [ProjectScoreListPageAsync]. - */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } - } - class AutoPager(private val firstPage: ProjectScoreListPageAsync) { fun forEach(action: Predicate, executor: Executor): CompletableFuture { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageResponse.kt new file mode 100644 index 00000000..de075aa9 --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageResponse.kt @@ -0,0 +1,194 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.ExcludeMissing +import com.braintrustdata.api.core.JsonField +import com.braintrustdata.api.core.JsonMissing +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.checkKnown +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.toImmutable +import com.braintrustdata.api.errors.BraintrustInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class ProjectScoreListPageResponse +private constructor( + private val objects: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("objects") + @ExcludeMissing + objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + + /** + * A list of project_score objects + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun objects(): List = objects.getRequired("objects") + + /** + * Returns the raw JSON value of [objects]. + * + * Unlike [objects], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("objects") @ExcludeMissing fun _objects(): JsonField> = objects + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ProjectScoreListPageResponse]. + * + * The following fields are required: + * ```java + * .objects() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProjectScoreListPageResponse]. */ + class Builder internal constructor() { + + private var objects: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(projectScoreListPageResponse: ProjectScoreListPageResponse) = apply { + objects = projectScoreListPageResponse.objects.map { it.toMutableList() } + additionalProperties = projectScoreListPageResponse.additionalProperties.toMutableMap() + } + + /** A list of project_score objects */ + fun objects(objects: List) = objects(JsonField.of(objects)) + + /** + * Sets [Builder.objects] to an arbitrary JSON value. + * + * You should usually call [Builder.objects] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun objects(objects: JsonField>) = apply { + this.objects = objects.map { it.toMutableList() } + } + + /** + * Adds a single [ProjectScore] to [objects]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addObject(object_: ProjectScore) = apply { + objects = + (objects ?: JsonField.of(mutableListOf())).also { + checkKnown("objects", it).add(object_) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [ProjectScoreListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .objects() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProjectScoreListPageResponse = + ProjectScoreListPageResponse( + checkRequired("objects", objects).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ProjectScoreListPageResponse = apply { + if (validated) { + return@apply + } + + objects().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (objects.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ProjectScoreListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ProjectScoreListPageResponse{objects=$objects, additionalProperties=$additionalProperties}" +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt index 3c17b1d3..7482d0a8 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.ProjectTagService -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -27,12 +17,19 @@ class ProjectTagListPage private constructor( private val projectTagsService: ProjectTagService, private val params: ProjectTagListParams, - private val response: Response, + private val response: ProjectTagListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): ProjectTagListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [ProjectTagListPageResponse], but gracefully handles missing data. + * + * @see [ProjectTagListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -47,20 +44,20 @@ private constructor( override fun toString() = "ProjectTagListPage{projectTagsService=$projectTagsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): Optional { @@ -75,103 +72,10 @@ private constructor( fun of( projectTagsService: ProjectTagService, params: ProjectTagListParams, - response: Response, + response: ProjectTagListPageResponse, ) = ProjectTagListPage(projectTagsService, params, response) } - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** Returns a mutable builder for constructing an instance of [ProjectTagListPage]. */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } - } - class AutoPager(private val firstPage: ProjectTagListPage) : Iterable { override fun iterator(): Iterator = iterator { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt index 7b33b899..533f9217 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.ProjectTagServiceAsync -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -28,12 +18,19 @@ class ProjectTagListPageAsync private constructor( private val projectTagsService: ProjectTagServiceAsync, private val params: ProjectTagListParams, - private val response: Response, + private val response: ProjectTagListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): ProjectTagListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [ProjectTagListPageResponse], but gracefully handles missing data. + * + * @see [ProjectTagListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -48,20 +45,20 @@ private constructor( override fun toString() = "ProjectTagListPageAsync{projectTagsService=$projectTagsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): CompletableFuture> { @@ -78,105 +75,10 @@ private constructor( fun of( projectTagsService: ProjectTagServiceAsync, params: ProjectTagListParams, - response: Response, + response: ProjectTagListPageResponse, ) = ProjectTagListPageAsync(projectTagsService, params, response) } - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [ProjectTagListPageAsync]. - */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } - } - class AutoPager(private val firstPage: ProjectTagListPageAsync) { fun forEach(action: Predicate, executor: Executor): CompletableFuture { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageResponse.kt new file mode 100644 index 00000000..b50ad2b4 --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageResponse.kt @@ -0,0 +1,194 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.ExcludeMissing +import com.braintrustdata.api.core.JsonField +import com.braintrustdata.api.core.JsonMissing +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.checkKnown +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.toImmutable +import com.braintrustdata.api.errors.BraintrustInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class ProjectTagListPageResponse +private constructor( + private val objects: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("objects") + @ExcludeMissing + objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + + /** + * A list of project_tag objects + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun objects(): List = objects.getRequired("objects") + + /** + * Returns the raw JSON value of [objects]. + * + * Unlike [objects], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("objects") @ExcludeMissing fun _objects(): JsonField> = objects + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ProjectTagListPageResponse]. + * + * The following fields are required: + * ```java + * .objects() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProjectTagListPageResponse]. */ + class Builder internal constructor() { + + private var objects: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(projectTagListPageResponse: ProjectTagListPageResponse) = apply { + objects = projectTagListPageResponse.objects.map { it.toMutableList() } + additionalProperties = projectTagListPageResponse.additionalProperties.toMutableMap() + } + + /** A list of project_tag objects */ + fun objects(objects: List) = objects(JsonField.of(objects)) + + /** + * Sets [Builder.objects] to an arbitrary JSON value. + * + * You should usually call [Builder.objects] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun objects(objects: JsonField>) = apply { + this.objects = objects.map { it.toMutableList() } + } + + /** + * Adds a single [ProjectTag] to [objects]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addObject(object_: ProjectTag) = apply { + objects = + (objects ?: JsonField.of(mutableListOf())).also { + checkKnown("objects", it).add(object_) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [ProjectTagListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .objects() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProjectTagListPageResponse = + ProjectTagListPageResponse( + checkRequired("objects", objects).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ProjectTagListPageResponse = apply { + if (validated) { + return@apply + } + + objects().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (objects.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ProjectTagListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ProjectTagListPageResponse{objects=$objects, additionalProperties=$additionalProperties}" +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt index 4098a2a8..587a1c5d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.PromptService -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -27,12 +17,19 @@ class PromptListPage private constructor( private val promptsService: PromptService, private val params: PromptListParams, - private val response: Response, + private val response: PromptListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): PromptListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [PromptListPageResponse], but gracefully handles missing data. + * + * @see [PromptListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -47,20 +44,20 @@ private constructor( override fun toString() = "PromptListPage{promptsService=$promptsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): Optional { @@ -72,101 +69,11 @@ private constructor( companion object { @JvmStatic - fun of(promptsService: PromptService, params: PromptListParams, response: Response) = - PromptListPage(promptsService, params, response) - } - - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** Returns a mutable builder for constructing an instance of [PromptListPage]. */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } + fun of( + promptsService: PromptService, + params: PromptListParams, + response: PromptListPageResponse, + ) = PromptListPage(promptsService, params, response) } class AutoPager(private val firstPage: PromptListPage) : Iterable { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt index d534335b..cfee8a95 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.PromptServiceAsync -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -28,12 +18,19 @@ class PromptListPageAsync private constructor( private val promptsService: PromptServiceAsync, private val params: PromptListParams, - private val response: Response, + private val response: PromptListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): PromptListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [PromptListPageResponse], but gracefully handles missing data. + * + * @see [PromptListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -48,20 +45,20 @@ private constructor( override fun toString() = "PromptListPageAsync{promptsService=$promptsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): CompletableFuture> { @@ -75,101 +72,11 @@ private constructor( companion object { @JvmStatic - fun of(promptsService: PromptServiceAsync, params: PromptListParams, response: Response) = - PromptListPageAsync(promptsService, params, response) - } - - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** Returns a mutable builder for constructing an instance of [PromptListPageAsync]. */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } + fun of( + promptsService: PromptServiceAsync, + params: PromptListParams, + response: PromptListPageResponse, + ) = PromptListPageAsync(promptsService, params, response) } class AutoPager(private val firstPage: PromptListPageAsync) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageResponse.kt new file mode 100644 index 00000000..5af60fcc --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageResponse.kt @@ -0,0 +1,192 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.ExcludeMissing +import com.braintrustdata.api.core.JsonField +import com.braintrustdata.api.core.JsonMissing +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.checkKnown +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.toImmutable +import com.braintrustdata.api.errors.BraintrustInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class PromptListPageResponse +private constructor( + private val objects: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("objects") @ExcludeMissing objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + + /** + * A list of prompt objects + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun objects(): List = objects.getRequired("objects") + + /** + * Returns the raw JSON value of [objects]. + * + * Unlike [objects], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("objects") @ExcludeMissing fun _objects(): JsonField> = objects + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [PromptListPageResponse]. + * + * The following fields are required: + * ```java + * .objects() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PromptListPageResponse]. */ + class Builder internal constructor() { + + private var objects: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(promptListPageResponse: PromptListPageResponse) = apply { + objects = promptListPageResponse.objects.map { it.toMutableList() } + additionalProperties = promptListPageResponse.additionalProperties.toMutableMap() + } + + /** A list of prompt objects */ + fun objects(objects: List) = objects(JsonField.of(objects)) + + /** + * Sets [Builder.objects] to an arbitrary JSON value. + * + * You should usually call [Builder.objects] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun objects(objects: JsonField>) = apply { + this.objects = objects.map { it.toMutableList() } + } + + /** + * Adds a single [Prompt] to [objects]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addObject(object_: Prompt) = apply { + objects = + (objects ?: JsonField.of(mutableListOf())).also { + checkKnown("objects", it).add(object_) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [PromptListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .objects() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PromptListPageResponse = + PromptListPageResponse( + checkRequired("objects", objects).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PromptListPageResponse = apply { + if (validated) { + return@apply + } + + objects().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (objects.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is PromptListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PromptListPageResponse{objects=$objects, additionalProperties=$additionalProperties}" +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt index 9449de10..7457585a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.RoleService -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -27,12 +17,19 @@ class RoleListPage private constructor( private val rolesService: RoleService, private val params: RoleListParams, - private val response: Response, + private val response: RoleListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): RoleListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [RoleListPageResponse], but gracefully handles missing data. + * + * @see [RoleListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -47,20 +44,20 @@ private constructor( override fun toString() = "RoleListPage{rolesService=$rolesService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): Optional { @@ -72,103 +69,10 @@ private constructor( companion object { @JvmStatic - fun of(rolesService: RoleService, params: RoleListParams, response: Response) = + fun of(rolesService: RoleService, params: RoleListParams, response: RoleListPageResponse) = RoleListPage(rolesService, params, response) } - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** Returns a mutable builder for constructing an instance of [RoleListPage]. */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } - } - class AutoPager(private val firstPage: RoleListPage) : Iterable { override fun iterator(): Iterator = iterator { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt index 1c36629f..12e641a6 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.RoleServiceAsync -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -28,12 +18,19 @@ class RoleListPageAsync private constructor( private val rolesService: RoleServiceAsync, private val params: RoleListParams, - private val response: Response, + private val response: RoleListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): RoleListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [RoleListPageResponse], but gracefully handles missing data. + * + * @see [RoleListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -48,20 +45,20 @@ private constructor( override fun toString() = "RoleListPageAsync{rolesService=$rolesService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): CompletableFuture> { @@ -75,101 +72,11 @@ private constructor( companion object { @JvmStatic - fun of(rolesService: RoleServiceAsync, params: RoleListParams, response: Response) = - RoleListPageAsync(rolesService, params, response) - } - - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** Returns a mutable builder for constructing an instance of [RoleListPageAsync]. */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } + fun of( + rolesService: RoleServiceAsync, + params: RoleListParams, + response: RoleListPageResponse, + ) = RoleListPageAsync(rolesService, params, response) } class AutoPager(private val firstPage: RoleListPageAsync) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageResponse.kt new file mode 100644 index 00000000..083c5ccd --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageResponse.kt @@ -0,0 +1,192 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.ExcludeMissing +import com.braintrustdata.api.core.JsonField +import com.braintrustdata.api.core.JsonMissing +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.checkKnown +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.toImmutable +import com.braintrustdata.api.errors.BraintrustInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class RoleListPageResponse +private constructor( + private val objects: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("objects") @ExcludeMissing objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + + /** + * A list of role objects + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun objects(): List = objects.getRequired("objects") + + /** + * Returns the raw JSON value of [objects]. + * + * Unlike [objects], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("objects") @ExcludeMissing fun _objects(): JsonField> = objects + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [RoleListPageResponse]. + * + * The following fields are required: + * ```java + * .objects() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoleListPageResponse]. */ + class Builder internal constructor() { + + private var objects: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(roleListPageResponse: RoleListPageResponse) = apply { + objects = roleListPageResponse.objects.map { it.toMutableList() } + additionalProperties = roleListPageResponse.additionalProperties.toMutableMap() + } + + /** A list of role objects */ + fun objects(objects: List) = objects(JsonField.of(objects)) + + /** + * Sets [Builder.objects] to an arbitrary JSON value. + * + * You should usually call [Builder.objects] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun objects(objects: JsonField>) = apply { + this.objects = objects.map { it.toMutableList() } + } + + /** + * Adds a single [Role] to [objects]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addObject(object_: Role) = apply { + objects = + (objects ?: JsonField.of(mutableListOf())).also { + checkKnown("objects", it).add(object_) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [RoleListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .objects() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RoleListPageResponse = + RoleListPageResponse( + checkRequired("objects", objects).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): RoleListPageResponse = apply { + if (validated) { + return@apply + } + + objects().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (objects.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is RoleListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RoleListPageResponse{objects=$objects, additionalProperties=$additionalProperties}" +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt index 0fa817b5..cf61c6a6 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.SpanIframeService -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -27,12 +17,19 @@ class SpanIframeListPage private constructor( private val spanIframesService: SpanIframeService, private val params: SpanIframeListParams, - private val response: Response, + private val response: SpanIframeListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): SpanIframeListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [SpanIframeListPageResponse], but gracefully handles missing data. + * + * @see [SpanIframeListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -47,20 +44,20 @@ private constructor( override fun toString() = "SpanIframeListPage{spanIframesService=$spanIframesService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): Optional { @@ -75,103 +72,10 @@ private constructor( fun of( spanIframesService: SpanIframeService, params: SpanIframeListParams, - response: Response, + response: SpanIframeListPageResponse, ) = SpanIframeListPage(spanIframesService, params, response) } - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** Returns a mutable builder for constructing an instance of [SpanIframeListPage]. */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } - } - class AutoPager(private val firstPage: SpanIframeListPage) : Iterable { override fun iterator(): Iterator = iterator { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt index 2a5e98a8..fd338a6a 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.SpanIframeServiceAsync -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -28,12 +18,19 @@ class SpanIframeListPageAsync private constructor( private val spanIframesService: SpanIframeServiceAsync, private val params: SpanIframeListParams, - private val response: Response, + private val response: SpanIframeListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): SpanIframeListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [SpanIframeListPageResponse], but gracefully handles missing data. + * + * @see [SpanIframeListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -48,20 +45,20 @@ private constructor( override fun toString() = "SpanIframeListPageAsync{spanIframesService=$spanIframesService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): CompletableFuture> { @@ -78,105 +75,10 @@ private constructor( fun of( spanIframesService: SpanIframeServiceAsync, params: SpanIframeListParams, - response: Response, + response: SpanIframeListPageResponse, ) = SpanIframeListPageAsync(spanIframesService, params, response) } - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [SpanIframeListPageAsync]. - */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } - } - class AutoPager(private val firstPage: SpanIframeListPageAsync) { fun forEach(action: Predicate, executor: Executor): CompletableFuture { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageResponse.kt new file mode 100644 index 00000000..f6d22bda --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageResponse.kt @@ -0,0 +1,194 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.ExcludeMissing +import com.braintrustdata.api.core.JsonField +import com.braintrustdata.api.core.JsonMissing +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.checkKnown +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.toImmutable +import com.braintrustdata.api.errors.BraintrustInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class SpanIframeListPageResponse +private constructor( + private val objects: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("objects") + @ExcludeMissing + objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + + /** + * A list of span_iframe objects + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun objects(): List = objects.getRequired("objects") + + /** + * Returns the raw JSON value of [objects]. + * + * Unlike [objects], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("objects") @ExcludeMissing fun _objects(): JsonField> = objects + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [SpanIframeListPageResponse]. + * + * The following fields are required: + * ```java + * .objects() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpanIframeListPageResponse]. */ + class Builder internal constructor() { + + private var objects: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(spanIframeListPageResponse: SpanIframeListPageResponse) = apply { + objects = spanIframeListPageResponse.objects.map { it.toMutableList() } + additionalProperties = spanIframeListPageResponse.additionalProperties.toMutableMap() + } + + /** A list of span_iframe objects */ + fun objects(objects: List) = objects(JsonField.of(objects)) + + /** + * Sets [Builder.objects] to an arbitrary JSON value. + * + * You should usually call [Builder.objects] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun objects(objects: JsonField>) = apply { + this.objects = objects.map { it.toMutableList() } + } + + /** + * Adds a single [SpanIFrame] to [objects]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addObject(object_: SpanIFrame) = apply { + objects = + (objects ?: JsonField.of(mutableListOf())).also { + checkKnown("objects", it).add(object_) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [SpanIframeListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .objects() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpanIframeListPageResponse = + SpanIframeListPageResponse( + checkRequired("objects", objects).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): SpanIframeListPageResponse = apply { + if (validated) { + return@apply + } + + objects().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (objects.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is SpanIframeListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SpanIframeListPageResponse{objects=$objects, additionalProperties=$additionalProperties}" +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt index 0b685152..22e76313 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.UserService -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -27,12 +17,19 @@ class UserListPage private constructor( private val usersService: UserService, private val params: UserListParams, - private val response: Response, + private val response: UserListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): UserListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [UserListPageResponse], but gracefully handles missing data. + * + * @see [UserListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -47,20 +44,20 @@ private constructor( override fun toString() = "UserListPage{usersService=$usersService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): Optional { @@ -72,103 +69,10 @@ private constructor( companion object { @JvmStatic - fun of(usersService: UserService, params: UserListParams, response: Response) = + fun of(usersService: UserService, params: UserListParams, response: UserListPageResponse) = UserListPage(usersService, params, response) } - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** Returns a mutable builder for constructing an instance of [UserListPage]. */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } - } - class AutoPager(private val firstPage: UserListPage) : Iterable { override fun iterator(): Iterator = iterator { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt index 57c87b9d..6b7601a3 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.UserServiceAsync -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -28,12 +18,19 @@ class UserListPageAsync private constructor( private val usersService: UserServiceAsync, private val params: UserListParams, - private val response: Response, + private val response: UserListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): UserListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [UserListPageResponse], but gracefully handles missing data. + * + * @see [UserListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -48,20 +45,20 @@ private constructor( override fun toString() = "UserListPageAsync{usersService=$usersService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): CompletableFuture> { @@ -75,101 +72,11 @@ private constructor( companion object { @JvmStatic - fun of(usersService: UserServiceAsync, params: UserListParams, response: Response) = - UserListPageAsync(usersService, params, response) - } - - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** Returns a mutable builder for constructing an instance of [UserListPageAsync]. */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } + fun of( + usersService: UserServiceAsync, + params: UserListParams, + response: UserListPageResponse, + ) = UserListPageAsync(usersService, params, response) } class AutoPager(private val firstPage: UserListPageAsync) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageResponse.kt new file mode 100644 index 00000000..b38d950e --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageResponse.kt @@ -0,0 +1,192 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.ExcludeMissing +import com.braintrustdata.api.core.JsonField +import com.braintrustdata.api.core.JsonMissing +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.checkKnown +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.toImmutable +import com.braintrustdata.api.errors.BraintrustInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class UserListPageResponse +private constructor( + private val objects: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("objects") @ExcludeMissing objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + + /** + * A list of user objects + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun objects(): List = objects.getRequired("objects") + + /** + * Returns the raw JSON value of [objects]. + * + * Unlike [objects], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("objects") @ExcludeMissing fun _objects(): JsonField> = objects + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [UserListPageResponse]. + * + * The following fields are required: + * ```java + * .objects() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UserListPageResponse]. */ + class Builder internal constructor() { + + private var objects: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(userListPageResponse: UserListPageResponse) = apply { + objects = userListPageResponse.objects.map { it.toMutableList() } + additionalProperties = userListPageResponse.additionalProperties.toMutableMap() + } + + /** A list of user objects */ + fun objects(objects: List) = objects(JsonField.of(objects)) + + /** + * Sets [Builder.objects] to an arbitrary JSON value. + * + * You should usually call [Builder.objects] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun objects(objects: JsonField>) = apply { + this.objects = objects.map { it.toMutableList() } + } + + /** + * Adds a single [User] to [objects]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addObject(object_: User) = apply { + objects = + (objects ?: JsonField.of(mutableListOf())).also { + checkKnown("objects", it).add(object_) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [UserListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .objects() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UserListPageResponse = + UserListPageResponse( + checkRequired("objects", objects).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): UserListPageResponse = apply { + if (validated) { + return@apply + } + + objects().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (objects.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is UserListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UserListPageResponse{objects=$objects, additionalProperties=$additionalProperties}" +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt index 4f443811..7a9fbf97 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.blocking.ViewService -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -27,12 +17,19 @@ class ViewListPage private constructor( private val viewsService: ViewService, private val params: ViewListParams, - private val response: Response, + private val response: ViewListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): ViewListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [ViewListPageResponse], but gracefully handles missing data. + * + * @see [ViewListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -47,20 +44,20 @@ private constructor( override fun toString() = "ViewListPage{viewsService=$viewsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): Optional { @@ -72,103 +69,10 @@ private constructor( companion object { @JvmStatic - fun of(viewsService: ViewService, params: ViewListParams, response: Response) = + fun of(viewsService: ViewService, params: ViewListParams, response: ViewListPageResponse) = ViewListPage(viewsService, params, response) } - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** Returns a mutable builder for constructing an instance of [ViewListPage]. */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } - } - class AutoPager(private val firstPage: ViewListPage) : Iterable { override fun iterator(): Iterator = iterator { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt index 84a2bd26..20bae5b9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt @@ -2,17 +2,7 @@ package com.braintrustdata.api.models -import com.braintrustdata.api.core.ExcludeMissing -import com.braintrustdata.api.core.JsonField -import com.braintrustdata.api.core.JsonMissing -import com.braintrustdata.api.core.JsonValue -import com.braintrustdata.api.errors.BraintrustInvalidDataException import com.braintrustdata.api.services.async.ViewServiceAsync -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -28,12 +18,19 @@ class ViewListPageAsync private constructor( private val viewsService: ViewServiceAsync, private val params: ViewListParams, - private val response: Response, + private val response: ViewListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): ViewListPageResponse = response - fun objects(): List = response().objects() + /** + * Delegates to [ViewListPageResponse], but gracefully handles missing data. + * + * @see [ViewListPageResponse.objects] + */ + fun objects(): List = + response._objects().getOptional("objects").getOrNull() ?: emptyList() override fun equals(other: Any?): Boolean { if (this === other) { @@ -48,20 +45,20 @@ private constructor( override fun toString() = "ViewListPageAsync{viewsService=$viewsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - return !objects().isEmpty() - } + fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return if (params.endingBefore().isPresent) { - Optional.of(params.toBuilder().endingBefore(objects().first().id()).build()) - } else { - Optional.of(params.toBuilder().startingAfter(objects().last().id()).build()) - } + return Optional.of( + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() + } + ) } fun getNextPage(): CompletableFuture> { @@ -75,101 +72,11 @@ private constructor( companion object { @JvmStatic - fun of(viewsService: ViewServiceAsync, params: ViewListParams, response: Response) = - ViewListPageAsync(viewsService, params, response) - } - - class Response( - private val objects: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("objects") objects: JsonField> = JsonMissing.of() - ) : this(objects, mutableMapOf()) - - fun objects(): List = objects.getOptional("objects").getOrNull() ?: listOf() - - @JsonProperty("objects") - fun _objects(): Optional>> = Optional.ofNullable(objects) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - objects().map { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: BraintrustInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objects, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{objects=$objects, additionalProperties=$additionalProperties}" - - companion object { - - /** Returns a mutable builder for constructing an instance of [ViewListPageAsync]. */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var objects: JsonField> = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.objects = page.objects - this.additionalProperties.putAll(page.additionalProperties) - } - - fun objects(objects: List) = objects(JsonField.of(objects)) - - fun objects(objects: JsonField>) = apply { this.objects = objects } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(objects, additionalProperties.toMutableMap()) - } + fun of( + viewsService: ViewServiceAsync, + params: ViewListParams, + response: ViewListPageResponse, + ) = ViewListPageAsync(viewsService, params, response) } class AutoPager(private val firstPage: ViewListPageAsync) { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageResponse.kt new file mode 100644 index 00000000..47ad5868 --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageResponse.kt @@ -0,0 +1,192 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.ExcludeMissing +import com.braintrustdata.api.core.JsonField +import com.braintrustdata.api.core.JsonMissing +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.checkKnown +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.toImmutable +import com.braintrustdata.api.errors.BraintrustInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class ViewListPageResponse +private constructor( + private val objects: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("objects") @ExcludeMissing objects: JsonField> = JsonMissing.of() + ) : this(objects, mutableMapOf()) + + /** + * A list of view objects + * + * @throws BraintrustInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun objects(): List = objects.getRequired("objects") + + /** + * Returns the raw JSON value of [objects]. + * + * Unlike [objects], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("objects") @ExcludeMissing fun _objects(): JsonField> = objects + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ViewListPageResponse]. + * + * The following fields are required: + * ```java + * .objects() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ViewListPageResponse]. */ + class Builder internal constructor() { + + private var objects: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(viewListPageResponse: ViewListPageResponse) = apply { + objects = viewListPageResponse.objects.map { it.toMutableList() } + additionalProperties = viewListPageResponse.additionalProperties.toMutableMap() + } + + /** A list of view objects */ + fun objects(objects: List) = objects(JsonField.of(objects)) + + /** + * Sets [Builder.objects] to an arbitrary JSON value. + * + * You should usually call [Builder.objects] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun objects(objects: JsonField>) = apply { + this.objects = objects.map { it.toMutableList() } + } + + /** + * Adds a single [View] to [objects]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addObject(object_: View) = apply { + objects = + (objects ?: JsonField.of(mutableListOf())).also { + checkKnown("objects", it).add(object_) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) + } + + /** + * Returns an immutable instance of [ViewListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .objects() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ViewListPageResponse = + ViewListPageResponse( + checkRequired("objects", objects).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ViewListPageResponse = apply { + if (validated) { + return@apply + } + + objects().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: BraintrustInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (objects.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ViewListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ViewListPageResponse{objects=$objects, additionalProperties=$additionalProperties}" +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AclServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AclServiceAsyncImpl.kt index 002305b8..bea90cc4 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AclServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AclServiceAsyncImpl.kt @@ -22,6 +22,7 @@ import com.braintrustdata.api.models.AclCreateParams import com.braintrustdata.api.models.AclDeleteParams import com.braintrustdata.api.models.AclFindAndDeleteParams import com.braintrustdata.api.models.AclListPageAsync +import com.braintrustdata.api.models.AclListPageResponse import com.braintrustdata.api.models.AclListParams import com.braintrustdata.api.models.AclRetrieveParams import java.util.concurrent.CompletableFuture @@ -141,8 +142,8 @@ class AclServiceAsyncImpl internal constructor(private val clientOptions: Client } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsyncImpl.kt index 6ebbadb1..2c8c8b6b 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsyncImpl.kt @@ -20,6 +20,7 @@ import com.braintrustdata.api.models.AiSecretCreateParams import com.braintrustdata.api.models.AiSecretDeleteParams import com.braintrustdata.api.models.AiSecretFindAndDeleteParams import com.braintrustdata.api.models.AiSecretListPageAsync +import com.braintrustdata.api.models.AiSecretListPageResponse import com.braintrustdata.api.models.AiSecretListParams import com.braintrustdata.api.models.AiSecretReplaceParams import com.braintrustdata.api.models.AiSecretRetrieveParams @@ -178,8 +179,8 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsyncImpl.kt index 0d7a9262..a552fb23 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsyncImpl.kt @@ -19,6 +19,7 @@ import com.braintrustdata.api.models.ApiKey import com.braintrustdata.api.models.ApiKeyCreateParams import com.braintrustdata.api.models.ApiKeyDeleteParams import com.braintrustdata.api.models.ApiKeyListPageAsync +import com.braintrustdata.api.models.ApiKeyListPageResponse import com.braintrustdata.api.models.ApiKeyListParams import com.braintrustdata.api.models.ApiKeyRetrieveParams import com.braintrustdata.api.models.CreateApiKeyOutput @@ -125,8 +126,8 @@ class ApiKeyServiceAsyncImpl internal constructor(private val clientOptions: Cli } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsyncImpl.kt index ae50c95f..003396d2 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsyncImpl.kt @@ -23,6 +23,7 @@ import com.braintrustdata.api.models.DatasetFetchParams import com.braintrustdata.api.models.DatasetFetchPostParams import com.braintrustdata.api.models.DatasetInsertParams import com.braintrustdata.api.models.DatasetListPageAsync +import com.braintrustdata.api.models.DatasetListPageResponse import com.braintrustdata.api.models.DatasetListParams import com.braintrustdata.api.models.DatasetRetrieveParams import com.braintrustdata.api.models.DatasetSummarizeParams @@ -206,8 +207,8 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsyncImpl.kt index 0bf6bb72..8068d0df 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsyncImpl.kt @@ -23,6 +23,7 @@ import com.braintrustdata.api.models.ExperimentFetchParams import com.braintrustdata.api.models.ExperimentFetchPostParams import com.braintrustdata.api.models.ExperimentInsertParams import com.braintrustdata.api.models.ExperimentListPageAsync +import com.braintrustdata.api.models.ExperimentListPageResponse import com.braintrustdata.api.models.ExperimentListParams import com.braintrustdata.api.models.ExperimentRetrieveParams import com.braintrustdata.api.models.ExperimentSummarizeParams @@ -206,8 +207,8 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsyncImpl.kt index 2fc58ddd..30e5ddb3 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsyncImpl.kt @@ -21,6 +21,7 @@ import com.braintrustdata.api.models.FunctionDeleteParams import com.braintrustdata.api.models.FunctionInvokeParams import com.braintrustdata.api.models.FunctionInvokeResponse import com.braintrustdata.api.models.FunctionListPageAsync +import com.braintrustdata.api.models.FunctionListPageResponse import com.braintrustdata.api.models.FunctionListParams import com.braintrustdata.api.models.FunctionReplaceParams import com.braintrustdata.api.models.FunctionRetrieveParams @@ -180,8 +181,8 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/GroupServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/GroupServiceAsyncImpl.kt index 680df37e..e22c95a3 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/GroupServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/GroupServiceAsyncImpl.kt @@ -19,6 +19,7 @@ import com.braintrustdata.api.models.Group import com.braintrustdata.api.models.GroupCreateParams import com.braintrustdata.api.models.GroupDeleteParams import com.braintrustdata.api.models.GroupListPageAsync +import com.braintrustdata.api.models.GroupListPageResponse import com.braintrustdata.api.models.GroupListParams import com.braintrustdata.api.models.GroupReplaceParams import com.braintrustdata.api.models.GroupRetrieveParams @@ -170,8 +171,8 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsyncImpl.kt index a314f29b..317c1bbc 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsyncImpl.kt @@ -18,6 +18,7 @@ import com.braintrustdata.api.core.prepareAsync import com.braintrustdata.api.models.Organization import com.braintrustdata.api.models.OrganizationDeleteParams import com.braintrustdata.api.models.OrganizationListPageAsync +import com.braintrustdata.api.models.OrganizationListPageResponse import com.braintrustdata.api.models.OrganizationListParams import com.braintrustdata.api.models.OrganizationRetrieveParams import com.braintrustdata.api.models.OrganizationUpdateParams @@ -136,8 +137,8 @@ class OrganizationServiceAsyncImpl internal constructor(private val clientOption } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsyncImpl.kt index a3a90f99..c27a72ce 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsyncImpl.kt @@ -19,6 +19,7 @@ import com.braintrustdata.api.models.ProjectScore import com.braintrustdata.api.models.ProjectScoreCreateParams import com.braintrustdata.api.models.ProjectScoreDeleteParams import com.braintrustdata.api.models.ProjectScoreListPageAsync +import com.braintrustdata.api.models.ProjectScoreListPageResponse import com.braintrustdata.api.models.ProjectScoreListParams import com.braintrustdata.api.models.ProjectScoreReplaceParams import com.braintrustdata.api.models.ProjectScoreRetrieveParams @@ -170,8 +171,8 @@ class ProjectScoreServiceAsyncImpl internal constructor(private val clientOption } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsyncImpl.kt index ed4539e4..4945d7a9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsyncImpl.kt @@ -19,6 +19,7 @@ import com.braintrustdata.api.models.Project import com.braintrustdata.api.models.ProjectCreateParams import com.braintrustdata.api.models.ProjectDeleteParams import com.braintrustdata.api.models.ProjectListPageAsync +import com.braintrustdata.api.models.ProjectListPageResponse import com.braintrustdata.api.models.ProjectListParams import com.braintrustdata.api.models.ProjectRetrieveParams import com.braintrustdata.api.models.ProjectUpdateParams @@ -174,8 +175,8 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsyncImpl.kt index ca6f111e..f83e7507 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsyncImpl.kt @@ -19,6 +19,7 @@ import com.braintrustdata.api.models.ProjectTag import com.braintrustdata.api.models.ProjectTagCreateParams import com.braintrustdata.api.models.ProjectTagDeleteParams import com.braintrustdata.api.models.ProjectTagListPageAsync +import com.braintrustdata.api.models.ProjectTagListPageResponse import com.braintrustdata.api.models.ProjectTagListParams import com.braintrustdata.api.models.ProjectTagReplaceParams import com.braintrustdata.api.models.ProjectTagRetrieveParams @@ -170,8 +171,8 @@ class ProjectTagServiceAsyncImpl internal constructor(private val clientOptions: } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/PromptServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/PromptServiceAsyncImpl.kt index 0c56cbf4..eb1c6ce3 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/PromptServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/PromptServiceAsyncImpl.kt @@ -19,6 +19,7 @@ import com.braintrustdata.api.models.Prompt import com.braintrustdata.api.models.PromptCreateParams import com.braintrustdata.api.models.PromptDeleteParams import com.braintrustdata.api.models.PromptListPageAsync +import com.braintrustdata.api.models.PromptListPageResponse import com.braintrustdata.api.models.PromptListParams import com.braintrustdata.api.models.PromptReplaceParams import com.braintrustdata.api.models.PromptRetrieveParams @@ -170,8 +171,8 @@ class PromptServiceAsyncImpl internal constructor(private val clientOptions: Cli } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/RoleServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/RoleServiceAsyncImpl.kt index 23ef1703..3081cfb0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/RoleServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/RoleServiceAsyncImpl.kt @@ -19,6 +19,7 @@ import com.braintrustdata.api.models.Role import com.braintrustdata.api.models.RoleCreateParams import com.braintrustdata.api.models.RoleDeleteParams import com.braintrustdata.api.models.RoleListPageAsync +import com.braintrustdata.api.models.RoleListPageResponse import com.braintrustdata.api.models.RoleListParams import com.braintrustdata.api.models.RoleReplaceParams import com.braintrustdata.api.models.RoleRetrieveParams @@ -170,8 +171,8 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsyncImpl.kt index c3699b95..7ce568c6 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsyncImpl.kt @@ -19,6 +19,7 @@ import com.braintrustdata.api.models.SpanIFrame import com.braintrustdata.api.models.SpanIframeCreateParams import com.braintrustdata.api.models.SpanIframeDeleteParams import com.braintrustdata.api.models.SpanIframeListPageAsync +import com.braintrustdata.api.models.SpanIframeListPageResponse import com.braintrustdata.api.models.SpanIframeListParams import com.braintrustdata.api.models.SpanIframeReplaceParams import com.braintrustdata.api.models.SpanIframeRetrieveParams @@ -170,8 +171,8 @@ class SpanIframeServiceAsyncImpl internal constructor(private val clientOptions: } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/UserServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/UserServiceAsyncImpl.kt index acd4a367..57d9116b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/UserServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/UserServiceAsyncImpl.kt @@ -16,6 +16,7 @@ import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepareAsync import com.braintrustdata.api.models.User import com.braintrustdata.api.models.UserListPageAsync +import com.braintrustdata.api.models.UserListPageResponse import com.braintrustdata.api.models.UserListParams import com.braintrustdata.api.models.UserRetrieveParams import java.util.concurrent.CompletableFuture @@ -77,8 +78,8 @@ class UserServiceAsyncImpl internal constructor(private val clientOptions: Clien } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ViewServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ViewServiceAsyncImpl.kt index 7e6818fd..423ac8e6 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ViewServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ViewServiceAsyncImpl.kt @@ -19,6 +19,7 @@ import com.braintrustdata.api.models.View import com.braintrustdata.api.models.ViewCreateParams import com.braintrustdata.api.models.ViewDeleteParams import com.braintrustdata.api.models.ViewListPageAsync +import com.braintrustdata.api.models.ViewListPageResponse import com.braintrustdata.api.models.ViewListParams import com.braintrustdata.api.models.ViewReplaceParams import com.braintrustdata.api.models.ViewRetrieveParams @@ -170,8 +171,8 @@ class ViewServiceAsyncImpl internal constructor(private val clientOptions: Clien } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AclServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AclServiceImpl.kt index 919a26cf..ebb50632 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AclServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AclServiceImpl.kt @@ -22,6 +22,7 @@ import com.braintrustdata.api.models.AclCreateParams import com.braintrustdata.api.models.AclDeleteParams import com.braintrustdata.api.models.AclFindAndDeleteParams import com.braintrustdata.api.models.AclListPage +import com.braintrustdata.api.models.AclListPageResponse import com.braintrustdata.api.models.AclListParams import com.braintrustdata.api.models.AclRetrieveParams @@ -121,8 +122,8 @@ class AclServiceImpl internal constructor(private val clientOptions: ClientOptio } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AiSecretServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AiSecretServiceImpl.kt index 8e88a4ea..da10ac38 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AiSecretServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AiSecretServiceImpl.kt @@ -20,6 +20,7 @@ import com.braintrustdata.api.models.AiSecretCreateParams import com.braintrustdata.api.models.AiSecretDeleteParams import com.braintrustdata.api.models.AiSecretFindAndDeleteParams import com.braintrustdata.api.models.AiSecretListPage +import com.braintrustdata.api.models.AiSecretListPageResponse import com.braintrustdata.api.models.AiSecretListParams import com.braintrustdata.api.models.AiSecretReplaceParams import com.braintrustdata.api.models.AiSecretRetrieveParams @@ -156,8 +157,8 @@ class AiSecretServiceImpl internal constructor(private val clientOptions: Client } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ApiKeyServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ApiKeyServiceImpl.kt index 81057230..d3adf2df 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ApiKeyServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ApiKeyServiceImpl.kt @@ -19,6 +19,7 @@ import com.braintrustdata.api.models.ApiKey import com.braintrustdata.api.models.ApiKeyCreateParams import com.braintrustdata.api.models.ApiKeyDeleteParams import com.braintrustdata.api.models.ApiKeyListPage +import com.braintrustdata.api.models.ApiKeyListPageResponse import com.braintrustdata.api.models.ApiKeyListParams import com.braintrustdata.api.models.ApiKeyRetrieveParams import com.braintrustdata.api.models.CreateApiKeyOutput @@ -109,8 +110,8 @@ class ApiKeyServiceImpl internal constructor(private val clientOptions: ClientOp } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/DatasetServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/DatasetServiceImpl.kt index 093ad4fa..2f8d8cbb 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/DatasetServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/DatasetServiceImpl.kt @@ -23,6 +23,7 @@ import com.braintrustdata.api.models.DatasetFetchParams import com.braintrustdata.api.models.DatasetFetchPostParams import com.braintrustdata.api.models.DatasetInsertParams import com.braintrustdata.api.models.DatasetListPage +import com.braintrustdata.api.models.DatasetListPageResponse import com.braintrustdata.api.models.DatasetListParams import com.braintrustdata.api.models.DatasetRetrieveParams import com.braintrustdata.api.models.DatasetSummarizeParams @@ -181,8 +182,8 @@ class DatasetServiceImpl internal constructor(private val clientOptions: ClientO } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ExperimentServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ExperimentServiceImpl.kt index a17af091..d7692a2a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ExperimentServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ExperimentServiceImpl.kt @@ -23,6 +23,7 @@ import com.braintrustdata.api.models.ExperimentFetchParams import com.braintrustdata.api.models.ExperimentFetchPostParams import com.braintrustdata.api.models.ExperimentInsertParams import com.braintrustdata.api.models.ExperimentListPage +import com.braintrustdata.api.models.ExperimentListPageResponse import com.braintrustdata.api.models.ExperimentListParams import com.braintrustdata.api.models.ExperimentRetrieveParams import com.braintrustdata.api.models.ExperimentSummarizeParams @@ -196,8 +197,8 @@ class ExperimentServiceImpl internal constructor(private val clientOptions: Clie } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceImpl.kt index fb56d1bd..e0659a16 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceImpl.kt @@ -21,6 +21,7 @@ import com.braintrustdata.api.models.FunctionDeleteParams import com.braintrustdata.api.models.FunctionInvokeParams import com.braintrustdata.api.models.FunctionInvokeResponse import com.braintrustdata.api.models.FunctionListPage +import com.braintrustdata.api.models.FunctionListPageResponse import com.braintrustdata.api.models.FunctionListParams import com.braintrustdata.api.models.FunctionReplaceParams import com.braintrustdata.api.models.FunctionRetrieveParams @@ -158,8 +159,8 @@ class FunctionServiceImpl internal constructor(private val clientOptions: Client } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/GroupServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/GroupServiceImpl.kt index 4b13b23e..09e6a822 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/GroupServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/GroupServiceImpl.kt @@ -19,6 +19,7 @@ import com.braintrustdata.api.models.Group import com.braintrustdata.api.models.GroupCreateParams import com.braintrustdata.api.models.GroupDeleteParams import com.braintrustdata.api.models.GroupListPage +import com.braintrustdata.api.models.GroupListPageResponse import com.braintrustdata.api.models.GroupListParams import com.braintrustdata.api.models.GroupReplaceParams import com.braintrustdata.api.models.GroupRetrieveParams @@ -142,8 +143,8 @@ class GroupServiceImpl internal constructor(private val clientOptions: ClientOpt } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/OrganizationServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/OrganizationServiceImpl.kt index dae0721d..b7601af9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/OrganizationServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/OrganizationServiceImpl.kt @@ -18,6 +18,7 @@ import com.braintrustdata.api.core.prepare import com.braintrustdata.api.models.Organization import com.braintrustdata.api.models.OrganizationDeleteParams import com.braintrustdata.api.models.OrganizationListPage +import com.braintrustdata.api.models.OrganizationListPageResponse import com.braintrustdata.api.models.OrganizationListParams import com.braintrustdata.api.models.OrganizationRetrieveParams import com.braintrustdata.api.models.OrganizationUpdateParams @@ -129,8 +130,8 @@ class OrganizationServiceImpl internal constructor(private val clientOptions: Cl } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreServiceImpl.kt index 6e7f231e..adc774d6 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreServiceImpl.kt @@ -19,6 +19,7 @@ import com.braintrustdata.api.models.ProjectScore import com.braintrustdata.api.models.ProjectScoreCreateParams import com.braintrustdata.api.models.ProjectScoreDeleteParams import com.braintrustdata.api.models.ProjectScoreListPage +import com.braintrustdata.api.models.ProjectScoreListPageResponse import com.braintrustdata.api.models.ProjectScoreListParams import com.braintrustdata.api.models.ProjectScoreReplaceParams import com.braintrustdata.api.models.ProjectScoreRetrieveParams @@ -160,8 +161,8 @@ class ProjectScoreServiceImpl internal constructor(private val clientOptions: Cl } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectServiceImpl.kt index 9ce11aad..5ce00751 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectServiceImpl.kt @@ -19,6 +19,7 @@ import com.braintrustdata.api.models.Project import com.braintrustdata.api.models.ProjectCreateParams import com.braintrustdata.api.models.ProjectDeleteParams import com.braintrustdata.api.models.ProjectListPage +import com.braintrustdata.api.models.ProjectListPageResponse import com.braintrustdata.api.models.ProjectListParams import com.braintrustdata.api.models.ProjectRetrieveParams import com.braintrustdata.api.models.ProjectUpdateParams @@ -149,8 +150,8 @@ class ProjectServiceImpl internal constructor(private val clientOptions: ClientO } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectTagServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectTagServiceImpl.kt index aab91cf9..d71558f6 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectTagServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectTagServiceImpl.kt @@ -19,6 +19,7 @@ import com.braintrustdata.api.models.ProjectTag import com.braintrustdata.api.models.ProjectTagCreateParams import com.braintrustdata.api.models.ProjectTagDeleteParams import com.braintrustdata.api.models.ProjectTagListPage +import com.braintrustdata.api.models.ProjectTagListPageResponse import com.braintrustdata.api.models.ProjectTagListParams import com.braintrustdata.api.models.ProjectTagReplaceParams import com.braintrustdata.api.models.ProjectTagRetrieveParams @@ -160,8 +161,8 @@ class ProjectTagServiceImpl internal constructor(private val clientOptions: Clie } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/PromptServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/PromptServiceImpl.kt index e1d9fc74..12ceab83 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/PromptServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/PromptServiceImpl.kt @@ -19,6 +19,7 @@ import com.braintrustdata.api.models.Prompt import com.braintrustdata.api.models.PromptCreateParams import com.braintrustdata.api.models.PromptDeleteParams import com.braintrustdata.api.models.PromptListPage +import com.braintrustdata.api.models.PromptListPageResponse import com.braintrustdata.api.models.PromptListParams import com.braintrustdata.api.models.PromptReplaceParams import com.braintrustdata.api.models.PromptRetrieveParams @@ -142,8 +143,8 @@ class PromptServiceImpl internal constructor(private val clientOptions: ClientOp } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/RoleServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/RoleServiceImpl.kt index b4be1645..97099679 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/RoleServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/RoleServiceImpl.kt @@ -19,6 +19,7 @@ import com.braintrustdata.api.models.Role import com.braintrustdata.api.models.RoleCreateParams import com.braintrustdata.api.models.RoleDeleteParams import com.braintrustdata.api.models.RoleListPage +import com.braintrustdata.api.models.RoleListPageResponse import com.braintrustdata.api.models.RoleListParams import com.braintrustdata.api.models.RoleReplaceParams import com.braintrustdata.api.models.RoleRetrieveParams @@ -141,8 +142,8 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/SpanIframeServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/SpanIframeServiceImpl.kt index 51cc3e3a..b522cf8b 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/SpanIframeServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/SpanIframeServiceImpl.kt @@ -19,6 +19,7 @@ import com.braintrustdata.api.models.SpanIFrame import com.braintrustdata.api.models.SpanIframeCreateParams import com.braintrustdata.api.models.SpanIframeDeleteParams import com.braintrustdata.api.models.SpanIframeListPage +import com.braintrustdata.api.models.SpanIframeListPageResponse import com.braintrustdata.api.models.SpanIframeListParams import com.braintrustdata.api.models.SpanIframeReplaceParams import com.braintrustdata.api.models.SpanIframeRetrieveParams @@ -160,8 +161,8 @@ class SpanIframeServiceImpl internal constructor(private val clientOptions: Clie } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/UserServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/UserServiceImpl.kt index 821373cd..8629234a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/UserServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/UserServiceImpl.kt @@ -16,6 +16,7 @@ import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepare import com.braintrustdata.api.models.User import com.braintrustdata.api.models.UserListPage +import com.braintrustdata.api.models.UserListPageResponse import com.braintrustdata.api.models.UserListParams import com.braintrustdata.api.models.UserRetrieveParams @@ -66,8 +67,8 @@ class UserServiceImpl internal constructor(private val clientOptions: ClientOpti } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ViewServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ViewServiceImpl.kt index f1792d0b..c7af6b57 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ViewServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ViewServiceImpl.kt @@ -19,6 +19,7 @@ import com.braintrustdata.api.models.View import com.braintrustdata.api.models.ViewCreateParams import com.braintrustdata.api.models.ViewDeleteParams import com.braintrustdata.api.models.ViewListPage +import com.braintrustdata.api.models.ViewListPageResponse import com.braintrustdata.api.models.ViewListParams import com.braintrustdata.api.models.ViewReplaceParams import com.braintrustdata.api.models.ViewRetrieveParams @@ -141,8 +142,8 @@ class ViewServiceImpl internal constructor(private val clientOptions: ClientOpti } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclListPageResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclListPageResponseTest.kt new file mode 100644 index 00000000..fdb2fe1a --- /dev/null +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AclListPageResponseTest.kt @@ -0,0 +1,79 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class AclListPageResponseTest { + + @Test + fun create() { + val aclListPageResponse = + AclListPageResponse.builder() + .addObject( + Acl.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + ._objectOrgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(AclObjectType.ORGANIZATION) + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .groupId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .permission(Permission.CREATE) + .restrictObjectType(AclObjectType.ORGANIZATION) + .roleId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .build() + + assertThat(aclListPageResponse.objects()) + .containsExactly( + Acl.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + ._objectOrgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(AclObjectType.ORGANIZATION) + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .groupId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .permission(Permission.CREATE) + .restrictObjectType(AclObjectType.ORGANIZATION) + .roleId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val aclListPageResponse = + AclListPageResponse.builder() + .addObject( + Acl.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + ._objectOrgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(AclObjectType.ORGANIZATION) + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .groupId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .permission(Permission.CREATE) + .restrictObjectType(AclObjectType.ORGANIZATION) + .roleId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .build() + + val roundtrippedAclListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(aclListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedAclListPageResponse).isEqualTo(aclListPageResponse) + } +} diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretListPageResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretListPageResponseTest.kt new file mode 100644 index 00000000..f37f7b6c --- /dev/null +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/AiSecretListPageResponseTest.kt @@ -0,0 +1,86 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class AiSecretListPageResponseTest { + + @Test + fun create() { + val aiSecretListPageResponse = + AiSecretListPageResponse.builder() + .addObject( + AISecret.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .metadata( + AISecret.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .previewSecret("preview_secret") + .type("type") + .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + ) + .build() + + assertThat(aiSecretListPageResponse.objects()) + .containsExactly( + AISecret.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .metadata( + AISecret.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .previewSecret("preview_secret") + .type("type") + .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val aiSecretListPageResponse = + AiSecretListPageResponse.builder() + .addObject( + AISecret.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .metadata( + AISecret.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .previewSecret("preview_secret") + .type("type") + .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + ) + .build() + + val roundtrippedAiSecretListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(aiSecretListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedAiSecretListPageResponse).isEqualTo(aiSecretListPageResponse) + } +} diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ApiKeyListPageResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ApiKeyListPageResponseTest.kt new file mode 100644 index 00000000..396312d3 --- /dev/null +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ApiKeyListPageResponseTest.kt @@ -0,0 +1,67 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ApiKeyListPageResponseTest { + + @Test + fun create() { + val apiKeyListPageResponse = + ApiKeyListPageResponse.builder() + .addObject( + ApiKey.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .previewName("preview_name") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .build() + + assertThat(apiKeyListPageResponse.objects()) + .containsExactly( + ApiKey.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .previewName("preview_name") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val apiKeyListPageResponse = + ApiKeyListPageResponse.builder() + .addObject( + ApiKey.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .previewName("preview_name") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .build() + + val roundtrippedApiKeyListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(apiKeyListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedApiKeyListPageResponse).isEqualTo(apiKeyListPageResponse) + } +} diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetListPageResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetListPageResponseTest.kt new file mode 100644 index 00000000..af744573 --- /dev/null +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/DatasetListPageResponseTest.kt @@ -0,0 +1,86 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class DatasetListPageResponseTest { + + @Test + fun create() { + val datasetListPageResponse = + DatasetListPageResponse.builder() + .addObject( + Dataset.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .metadata( + Dataset.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .build() + + assertThat(datasetListPageResponse.objects()) + .containsExactly( + Dataset.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .metadata( + Dataset.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val datasetListPageResponse = + DatasetListPageResponse.builder() + .addObject( + Dataset.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .metadata( + Dataset.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .build() + + val roundtrippedDatasetListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(datasetListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedDatasetListPageResponse).isEqualTo(datasetListPageResponse) + } +} diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentListPageResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentListPageResponseTest.kt new file mode 100644 index 00000000..867711cd --- /dev/null +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ExperimentListPageResponseTest.kt @@ -0,0 +1,140 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ExperimentListPageResponseTest { + + @Test + fun create() { + val experimentListPageResponse = + ExperimentListPageResponse.builder() + .addObject( + Experiment.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .public_(true) + .baseExpId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .commit("commit") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .datasetVersion("dataset_version") + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .metadata( + Experiment.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .repoInfo( + RepoInfo.builder() + .authorEmail("author_email") + .authorName("author_name") + .branch("branch") + .commit("commit") + .commitMessage("commit_message") + .commitTime("commit_time") + .dirty(true) + .gitDiff("git_diff") + .tag("tag") + .build() + ) + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .build() + + assertThat(experimentListPageResponse.objects()) + .containsExactly( + Experiment.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .public_(true) + .baseExpId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .commit("commit") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .datasetVersion("dataset_version") + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .metadata( + Experiment.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .repoInfo( + RepoInfo.builder() + .authorEmail("author_email") + .authorName("author_name") + .branch("branch") + .commit("commit") + .commitMessage("commit_message") + .commitTime("commit_time") + .dirty(true) + .gitDiff("git_diff") + .tag("tag") + .build() + ) + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val experimentListPageResponse = + ExperimentListPageResponse.builder() + .addObject( + Experiment.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .public_(true) + .baseExpId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .commit("commit") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .datasetVersion("dataset_version") + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .metadata( + Experiment.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .repoInfo( + RepoInfo.builder() + .authorEmail("author_email") + .authorName("author_name") + .branch("branch") + .commit("commit") + .commitMessage("commit_message") + .commitTime("commit_time") + .dirty(true) + .gitDiff("git_diff") + .tag("tag") + .build() + ) + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .build() + + val roundtrippedExperimentListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(experimentListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedExperimentListPageResponse).isEqualTo(experimentListPageResponse) + } +} diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionListPageResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionListPageResponseTest.kt new file mode 100644 index 00000000..f4021ef8 --- /dev/null +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/FunctionListPageResponseTest.kt @@ -0,0 +1,402 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class FunctionListPageResponseTest { + + @Test + fun create() { + val functionListPageResponse = + FunctionListPageResponse.builder() + .addObject( + Function.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + ._xactId("_xact_id") + .functionData( + Function.FunctionData.Prompt.builder() + .type(Function.FunctionData.Prompt.Type.PROMPT) + .build() + ) + .logId(Function.LogId.P) + .name("name") + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .slug("slug") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .functionSchema( + Function.FunctionSchema.builder() + .parameters(JsonValue.from(mapOf())) + .returns(JsonValue.from(mapOf())) + .build() + ) + .functionType(Function.FunctionType.LLM) + .metadata( + Function.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .origin( + Function.Origin.builder() + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(AclObjectType.ORGANIZATION) + .internal_(true) + .build() + ) + .promptData( + PromptData.builder() + .options( + PromptOptions.builder() + .model("model") + .params( + PromptOptions.Params.OpenAIModelParams.builder() + .frequencyPenalty(0.0) + .functionCall( + PromptOptions.Params.OpenAIModelParams + .FunctionCall + .UnionMember0 + .AUTO + ) + .maxCompletionTokens(0.0) + .maxTokens(0.0) + .n(0.0) + .presencePenalty(0.0) + .reasoningEffort( + PromptOptions.Params.OpenAIModelParams + .ReasoningEffort + .LOW + ) + .responseFormat( + PromptOptions.Params.OpenAIModelParams + .ResponseFormat + .JsonObject + .builder() + .type( + PromptOptions.Params.OpenAIModelParams + .ResponseFormat + .JsonObject + .Type + .JSON_OBJECT + ) + .build() + ) + .addStop("string") + .temperature(0.0) + .toolChoice( + PromptOptions.Params.OpenAIModelParams + .ToolChoice + .UnionMember0 + .AUTO + ) + .topP(0.0) + .useCache(true) + .build() + ) + .position("position") + .build() + ) + .origin( + PromptData.Origin.builder() + .projectId("project_id") + .promptId("prompt_id") + .promptVersion("prompt_version") + .build() + ) + .parser( + PromptData.Parser.builder() + .choiceScores( + PromptData.Parser.ChoiceScores.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .type(PromptData.Parser.Type.LLM_CLASSIFIER) + .useCot(true) + .build() + ) + .prompt( + PromptData.Prompt.Completion.builder() + .content("content") + .type(PromptData.Prompt.Completion.Type.COMPLETION) + .build() + ) + .addToolFunction( + PromptData.ToolFunction.Function.builder() + .id("id") + .type(PromptData.ToolFunction.Function.Type.FUNCTION) + .build() + ) + .build() + ) + .addTag("string") + .build() + ) + .build() + + assertThat(functionListPageResponse.objects()) + .containsExactly( + Function.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + ._xactId("_xact_id") + .functionData( + Function.FunctionData.Prompt.builder() + .type(Function.FunctionData.Prompt.Type.PROMPT) + .build() + ) + .logId(Function.LogId.P) + .name("name") + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .slug("slug") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .functionSchema( + Function.FunctionSchema.builder() + .parameters(JsonValue.from(mapOf())) + .returns(JsonValue.from(mapOf())) + .build() + ) + .functionType(Function.FunctionType.LLM) + .metadata( + Function.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .origin( + Function.Origin.builder() + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(AclObjectType.ORGANIZATION) + .internal_(true) + .build() + ) + .promptData( + PromptData.builder() + .options( + PromptOptions.builder() + .model("model") + .params( + PromptOptions.Params.OpenAIModelParams.builder() + .frequencyPenalty(0.0) + .functionCall( + PromptOptions.Params.OpenAIModelParams.FunctionCall + .UnionMember0 + .AUTO + ) + .maxCompletionTokens(0.0) + .maxTokens(0.0) + .n(0.0) + .presencePenalty(0.0) + .reasoningEffort( + PromptOptions.Params.OpenAIModelParams + .ReasoningEffort + .LOW + ) + .responseFormat( + PromptOptions.Params.OpenAIModelParams + .ResponseFormat + .JsonObject + .builder() + .type( + PromptOptions.Params.OpenAIModelParams + .ResponseFormat + .JsonObject + .Type + .JSON_OBJECT + ) + .build() + ) + .addStop("string") + .temperature(0.0) + .toolChoice( + PromptOptions.Params.OpenAIModelParams.ToolChoice + .UnionMember0 + .AUTO + ) + .topP(0.0) + .useCache(true) + .build() + ) + .position("position") + .build() + ) + .origin( + PromptData.Origin.builder() + .projectId("project_id") + .promptId("prompt_id") + .promptVersion("prompt_version") + .build() + ) + .parser( + PromptData.Parser.builder() + .choiceScores( + PromptData.Parser.ChoiceScores.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .type(PromptData.Parser.Type.LLM_CLASSIFIER) + .useCot(true) + .build() + ) + .prompt( + PromptData.Prompt.Completion.builder() + .content("content") + .type(PromptData.Prompt.Completion.Type.COMPLETION) + .build() + ) + .addToolFunction( + PromptData.ToolFunction.Function.builder() + .id("id") + .type(PromptData.ToolFunction.Function.Type.FUNCTION) + .build() + ) + .build() + ) + .addTag("string") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val functionListPageResponse = + FunctionListPageResponse.builder() + .addObject( + Function.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + ._xactId("_xact_id") + .functionData( + Function.FunctionData.Prompt.builder() + .type(Function.FunctionData.Prompt.Type.PROMPT) + .build() + ) + .logId(Function.LogId.P) + .name("name") + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .slug("slug") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .functionSchema( + Function.FunctionSchema.builder() + .parameters(JsonValue.from(mapOf())) + .returns(JsonValue.from(mapOf())) + .build() + ) + .functionType(Function.FunctionType.LLM) + .metadata( + Function.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .origin( + Function.Origin.builder() + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(AclObjectType.ORGANIZATION) + .internal_(true) + .build() + ) + .promptData( + PromptData.builder() + .options( + PromptOptions.builder() + .model("model") + .params( + PromptOptions.Params.OpenAIModelParams.builder() + .frequencyPenalty(0.0) + .functionCall( + PromptOptions.Params.OpenAIModelParams + .FunctionCall + .UnionMember0 + .AUTO + ) + .maxCompletionTokens(0.0) + .maxTokens(0.0) + .n(0.0) + .presencePenalty(0.0) + .reasoningEffort( + PromptOptions.Params.OpenAIModelParams + .ReasoningEffort + .LOW + ) + .responseFormat( + PromptOptions.Params.OpenAIModelParams + .ResponseFormat + .JsonObject + .builder() + .type( + PromptOptions.Params.OpenAIModelParams + .ResponseFormat + .JsonObject + .Type + .JSON_OBJECT + ) + .build() + ) + .addStop("string") + .temperature(0.0) + .toolChoice( + PromptOptions.Params.OpenAIModelParams + .ToolChoice + .UnionMember0 + .AUTO + ) + .topP(0.0) + .useCache(true) + .build() + ) + .position("position") + .build() + ) + .origin( + PromptData.Origin.builder() + .projectId("project_id") + .promptId("prompt_id") + .promptVersion("prompt_version") + .build() + ) + .parser( + PromptData.Parser.builder() + .choiceScores( + PromptData.Parser.ChoiceScores.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .type(PromptData.Parser.Type.LLM_CLASSIFIER) + .useCot(true) + .build() + ) + .prompt( + PromptData.Prompt.Completion.builder() + .content("content") + .type(PromptData.Prompt.Completion.Type.COMPLETION) + .build() + ) + .addToolFunction( + PromptData.ToolFunction.Function.builder() + .id("id") + .type(PromptData.ToolFunction.Function.Type.FUNCTION) + .build() + ) + .build() + ) + .addTag("string") + .build() + ) + .build() + + val roundtrippedFunctionListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(functionListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedFunctionListPageResponse).isEqualTo(functionListPageResponse) + } +} diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupListPageResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupListPageResponseTest.kt new file mode 100644 index 00000000..136b59ee --- /dev/null +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/GroupListPageResponseTest.kt @@ -0,0 +1,76 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class GroupListPageResponseTest { + + @Test + fun create() { + val groupListPageResponse = + GroupListPageResponse.builder() + .addObject( + Group.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .addMemberGroup("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addMemberUser("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .build() + + assertThat(groupListPageResponse.objects()) + .containsExactly( + Group.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .addMemberGroup("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addMemberUser("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val groupListPageResponse = + GroupListPageResponse.builder() + .addObject( + Group.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .addMemberGroup("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addMemberUser("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .build() + + val roundtrippedGroupListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(groupListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedGroupListPageResponse).isEqualTo(groupListPageResponse) + } +} diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationListPageResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationListPageResponseTest.kt new file mode 100644 index 00000000..a425684a --- /dev/null +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/OrganizationListPageResponseTest.kt @@ -0,0 +1,70 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class OrganizationListPageResponseTest { + + @Test + fun create() { + val organizationListPageResponse = + OrganizationListPageResponse.builder() + .addObject( + Organization.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .apiUrl("api_url") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .isUniversalApi(true) + .proxyUrl("proxy_url") + .realtimeUrl("realtime_url") + .build() + ) + .build() + + assertThat(organizationListPageResponse.objects()) + .containsExactly( + Organization.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .apiUrl("api_url") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .isUniversalApi(true) + .proxyUrl("proxy_url") + .realtimeUrl("realtime_url") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val organizationListPageResponse = + OrganizationListPageResponse.builder() + .addObject( + Organization.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .apiUrl("api_url") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .isUniversalApi(true) + .proxyUrl("proxy_url") + .realtimeUrl("realtime_url") + .build() + ) + .build() + + val roundtrippedOrganizationListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(organizationListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedOrganizationListPageResponse).isEqualTo(organizationListPageResponse) + } +} diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectListPageResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectListPageResponseTest.kt new file mode 100644 index 00000000..1e9fdd55 --- /dev/null +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectListPageResponseTest.kt @@ -0,0 +1,109 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ProjectListPageResponseTest { + + @Test + fun create() { + val projectListPageResponse = + ProjectListPageResponse.builder() + .addObject( + Project.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .settings( + ProjectSettings.builder() + .baselineExperimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .comparisonKey("comparison_key") + .addSpanFieldOrder( + ProjectSettings.SpanFieldOrder.builder() + .columnId("column_id") + .objectType("object_type") + .position("position") + .layout(ProjectSettings.SpanFieldOrder.Layout.FULL) + .build() + ) + .build() + ) + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .build() + + assertThat(projectListPageResponse.objects()) + .containsExactly( + Project.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .settings( + ProjectSettings.builder() + .baselineExperimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .comparisonKey("comparison_key") + .addSpanFieldOrder( + ProjectSettings.SpanFieldOrder.builder() + .columnId("column_id") + .objectType("object_type") + .position("position") + .layout(ProjectSettings.SpanFieldOrder.Layout.FULL) + .build() + ) + .build() + ) + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val projectListPageResponse = + ProjectListPageResponse.builder() + .addObject( + Project.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .settings( + ProjectSettings.builder() + .baselineExperimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .comparisonKey("comparison_key") + .addSpanFieldOrder( + ProjectSettings.SpanFieldOrder.builder() + .columnId("column_id") + .objectType("object_type") + .position("position") + .layout(ProjectSettings.SpanFieldOrder.Layout.FULL) + .build() + ) + .build() + ) + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .build() + + val roundtrippedProjectListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(projectListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedProjectListPageResponse).isEqualTo(projectListPageResponse) + } +} diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreListPageResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreListPageResponseTest.kt new file mode 100644 index 00000000..27b1a1d2 --- /dev/null +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectScoreListPageResponseTest.kt @@ -0,0 +1,143 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ProjectScoreListPageResponseTest { + + @Test + fun create() { + val projectScoreListPageResponse = + ProjectScoreListPageResponse.builder() + .addObject( + ProjectScore.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .scoreType(ProjectScoreType.SLIDER) + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .categoriesOfCategorical( + listOf(ProjectScoreCategory.builder().name("name").value(0.0).build()) + ) + .config( + ProjectScoreConfig.builder() + .destination("destination") + .multiSelect(true) + .online( + OnlineScoreConfig.builder() + .samplingRate(0.0) + .addScorer( + OnlineScoreConfig.Scorer.Function.builder() + .id("id") + .type( + OnlineScoreConfig.Scorer.Function.Type.FUNCTION + ) + .build() + ) + .applyToRootSpan(true) + .addApplyToSpanName("string") + .build() + ) + .build() + ) + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .position("position") + .build() + ) + .build() + + assertThat(projectScoreListPageResponse.objects()) + .containsExactly( + ProjectScore.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .scoreType(ProjectScoreType.SLIDER) + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .categoriesOfCategorical( + listOf(ProjectScoreCategory.builder().name("name").value(0.0).build()) + ) + .config( + ProjectScoreConfig.builder() + .destination("destination") + .multiSelect(true) + .online( + OnlineScoreConfig.builder() + .samplingRate(0.0) + .addScorer( + OnlineScoreConfig.Scorer.Function.builder() + .id("id") + .type(OnlineScoreConfig.Scorer.Function.Type.FUNCTION) + .build() + ) + .applyToRootSpan(true) + .addApplyToSpanName("string") + .build() + ) + .build() + ) + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .position("position") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val projectScoreListPageResponse = + ProjectScoreListPageResponse.builder() + .addObject( + ProjectScore.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .scoreType(ProjectScoreType.SLIDER) + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .categoriesOfCategorical( + listOf(ProjectScoreCategory.builder().name("name").value(0.0).build()) + ) + .config( + ProjectScoreConfig.builder() + .destination("destination") + .multiSelect(true) + .online( + OnlineScoreConfig.builder() + .samplingRate(0.0) + .addScorer( + OnlineScoreConfig.Scorer.Function.builder() + .id("id") + .type( + OnlineScoreConfig.Scorer.Function.Type.FUNCTION + ) + .build() + ) + .applyToRootSpan(true) + .addApplyToSpanName("string") + .build() + ) + .build() + ) + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .position("position") + .build() + ) + .build() + + val roundtrippedProjectScoreListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(projectScoreListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedProjectScoreListPageResponse).isEqualTo(projectScoreListPageResponse) + } +} diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagListPageResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagListPageResponseTest.kt new file mode 100644 index 00000000..4dd2fc1f --- /dev/null +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ProjectTagListPageResponseTest.kt @@ -0,0 +1,70 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ProjectTagListPageResponseTest { + + @Test + fun create() { + val projectTagListPageResponse = + ProjectTagListPageResponse.builder() + .addObject( + ProjectTag.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .color("color") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .build() + ) + .build() + + assertThat(projectTagListPageResponse.objects()) + .containsExactly( + ProjectTag.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .color("color") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val projectTagListPageResponse = + ProjectTagListPageResponse.builder() + .addObject( + ProjectTag.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .color("color") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .build() + ) + .build() + + val roundtrippedProjectTagListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(projectTagListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedProjectTagListPageResponse).isEqualTo(projectTagListPageResponse) + } +} diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptListPageResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptListPageResponseTest.kt new file mode 100644 index 00000000..9894bafc --- /dev/null +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/PromptListPageResponseTest.kt @@ -0,0 +1,348 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PromptListPageResponseTest { + + @Test + fun create() { + val promptListPageResponse = + PromptListPageResponse.builder() + .addObject( + Prompt.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + ._xactId("_xact_id") + .logId(Prompt.LogId.P) + .name("name") + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .slug("slug") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .functionType(Prompt.FunctionType.LLM) + .metadata( + Prompt.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .promptData( + PromptData.builder() + .options( + PromptOptions.builder() + .model("model") + .params( + PromptOptions.Params.OpenAIModelParams.builder() + .frequencyPenalty(0.0) + .functionCall( + PromptOptions.Params.OpenAIModelParams + .FunctionCall + .UnionMember0 + .AUTO + ) + .maxCompletionTokens(0.0) + .maxTokens(0.0) + .n(0.0) + .presencePenalty(0.0) + .reasoningEffort( + PromptOptions.Params.OpenAIModelParams + .ReasoningEffort + .LOW + ) + .responseFormat( + PromptOptions.Params.OpenAIModelParams + .ResponseFormat + .JsonObject + .builder() + .type( + PromptOptions.Params.OpenAIModelParams + .ResponseFormat + .JsonObject + .Type + .JSON_OBJECT + ) + .build() + ) + .addStop("string") + .temperature(0.0) + .toolChoice( + PromptOptions.Params.OpenAIModelParams + .ToolChoice + .UnionMember0 + .AUTO + ) + .topP(0.0) + .useCache(true) + .build() + ) + .position("position") + .build() + ) + .origin( + PromptData.Origin.builder() + .projectId("project_id") + .promptId("prompt_id") + .promptVersion("prompt_version") + .build() + ) + .parser( + PromptData.Parser.builder() + .choiceScores( + PromptData.Parser.ChoiceScores.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .type(PromptData.Parser.Type.LLM_CLASSIFIER) + .useCot(true) + .build() + ) + .prompt( + PromptData.Prompt.Completion.builder() + .content("content") + .type(PromptData.Prompt.Completion.Type.COMPLETION) + .build() + ) + .addToolFunction( + PromptData.ToolFunction.Function.builder() + .id("id") + .type(PromptData.ToolFunction.Function.Type.FUNCTION) + .build() + ) + .build() + ) + .addTag("string") + .build() + ) + .build() + + assertThat(promptListPageResponse.objects()) + .containsExactly( + Prompt.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + ._xactId("_xact_id") + .logId(Prompt.LogId.P) + .name("name") + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .slug("slug") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .functionType(Prompt.FunctionType.LLM) + .metadata( + Prompt.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .promptData( + PromptData.builder() + .options( + PromptOptions.builder() + .model("model") + .params( + PromptOptions.Params.OpenAIModelParams.builder() + .frequencyPenalty(0.0) + .functionCall( + PromptOptions.Params.OpenAIModelParams.FunctionCall + .UnionMember0 + .AUTO + ) + .maxCompletionTokens(0.0) + .maxTokens(0.0) + .n(0.0) + .presencePenalty(0.0) + .reasoningEffort( + PromptOptions.Params.OpenAIModelParams + .ReasoningEffort + .LOW + ) + .responseFormat( + PromptOptions.Params.OpenAIModelParams + .ResponseFormat + .JsonObject + .builder() + .type( + PromptOptions.Params.OpenAIModelParams + .ResponseFormat + .JsonObject + .Type + .JSON_OBJECT + ) + .build() + ) + .addStop("string") + .temperature(0.0) + .toolChoice( + PromptOptions.Params.OpenAIModelParams.ToolChoice + .UnionMember0 + .AUTO + ) + .topP(0.0) + .useCache(true) + .build() + ) + .position("position") + .build() + ) + .origin( + PromptData.Origin.builder() + .projectId("project_id") + .promptId("prompt_id") + .promptVersion("prompt_version") + .build() + ) + .parser( + PromptData.Parser.builder() + .choiceScores( + PromptData.Parser.ChoiceScores.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .type(PromptData.Parser.Type.LLM_CLASSIFIER) + .useCot(true) + .build() + ) + .prompt( + PromptData.Prompt.Completion.builder() + .content("content") + .type(PromptData.Prompt.Completion.Type.COMPLETION) + .build() + ) + .addToolFunction( + PromptData.ToolFunction.Function.builder() + .id("id") + .type(PromptData.ToolFunction.Function.Type.FUNCTION) + .build() + ) + .build() + ) + .addTag("string") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val promptListPageResponse = + PromptListPageResponse.builder() + .addObject( + Prompt.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + ._xactId("_xact_id") + .logId(Prompt.LogId.P) + .name("name") + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .slug("slug") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .functionType(Prompt.FunctionType.LLM) + .metadata( + Prompt.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .promptData( + PromptData.builder() + .options( + PromptOptions.builder() + .model("model") + .params( + PromptOptions.Params.OpenAIModelParams.builder() + .frequencyPenalty(0.0) + .functionCall( + PromptOptions.Params.OpenAIModelParams + .FunctionCall + .UnionMember0 + .AUTO + ) + .maxCompletionTokens(0.0) + .maxTokens(0.0) + .n(0.0) + .presencePenalty(0.0) + .reasoningEffort( + PromptOptions.Params.OpenAIModelParams + .ReasoningEffort + .LOW + ) + .responseFormat( + PromptOptions.Params.OpenAIModelParams + .ResponseFormat + .JsonObject + .builder() + .type( + PromptOptions.Params.OpenAIModelParams + .ResponseFormat + .JsonObject + .Type + .JSON_OBJECT + ) + .build() + ) + .addStop("string") + .temperature(0.0) + .toolChoice( + PromptOptions.Params.OpenAIModelParams + .ToolChoice + .UnionMember0 + .AUTO + ) + .topP(0.0) + .useCache(true) + .build() + ) + .position("position") + .build() + ) + .origin( + PromptData.Origin.builder() + .projectId("project_id") + .promptId("prompt_id") + .promptVersion("prompt_version") + .build() + ) + .parser( + PromptData.Parser.builder() + .choiceScores( + PromptData.Parser.ChoiceScores.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .type(PromptData.Parser.Type.LLM_CLASSIFIER) + .useCot(true) + .build() + ) + .prompt( + PromptData.Prompt.Completion.builder() + .content("content") + .type(PromptData.Prompt.Completion.Type.COMPLETION) + .build() + ) + .addToolFunction( + PromptData.ToolFunction.Function.builder() + .id("id") + .type(PromptData.ToolFunction.Function.Type.FUNCTION) + .build() + ) + .build() + ) + .addTag("string") + .build() + ) + .build() + + val roundtrippedPromptListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(promptListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedPromptListPageResponse).isEqualTo(promptListPageResponse) + } +} diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleListPageResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleListPageResponseTest.kt new file mode 100644 index 00000000..0cdd38e4 --- /dev/null +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/RoleListPageResponseTest.kt @@ -0,0 +1,91 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RoleListPageResponseTest { + + @Test + fun create() { + val roleListPageResponse = + RoleListPageResponse.builder() + .addObject( + Role.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .addMemberPermission( + Role.MemberPermission.builder() + .permission(Permission.CREATE) + .restrictObjectType(AclObjectType.ORGANIZATION) + .build() + ) + .addMemberRole("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .build() + + assertThat(roleListPageResponse.objects()) + .containsExactly( + Role.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .addMemberPermission( + Role.MemberPermission.builder() + .permission(Permission.CREATE) + .restrictObjectType(AclObjectType.ORGANIZATION) + .build() + ) + .addMemberRole("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val roleListPageResponse = + RoleListPageResponse.builder() + .addObject( + Role.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .addMemberPermission( + Role.MemberPermission.builder() + .permission(Permission.CREATE) + .restrictObjectType(AclObjectType.ORGANIZATION) + .build() + ) + .addMemberRole("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .build() + + val roundtrippedRoleListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(roleListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedRoleListPageResponse).isEqualTo(roleListPageResponse) + } +} diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeListPageResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeListPageResponseTest.kt new file mode 100644 index 00000000..86a3f694 --- /dev/null +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/SpanIframeListPageResponseTest.kt @@ -0,0 +1,76 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class SpanIframeListPageResponseTest { + + @Test + fun create() { + val spanIframeListPageResponse = + SpanIframeListPageResponse.builder() + .addObject( + SpanIFrame.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .url("url") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .postMessage(true) + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .build() + + assertThat(spanIframeListPageResponse.objects()) + .containsExactly( + SpanIFrame.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .url("url") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .postMessage(true) + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val spanIframeListPageResponse = + SpanIframeListPageResponse.builder() + .addObject( + SpanIFrame.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .url("url") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .postMessage(true) + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .build() + + val roundtrippedSpanIframeListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(spanIframeListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSpanIframeListPageResponse).isEqualTo(spanIframeListPageResponse) + } +} diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/UserListPageResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/UserListPageResponseTest.kt new file mode 100644 index 00000000..58f9ef44 --- /dev/null +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/UserListPageResponseTest.kt @@ -0,0 +1,67 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class UserListPageResponseTest { + + @Test + fun create() { + val userListPageResponse = + UserListPageResponse.builder() + .addObject( + User.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .avatarUrl("avatar_url") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .email("email") + .familyName("family_name") + .givenName("given_name") + .build() + ) + .build() + + assertThat(userListPageResponse.objects()) + .containsExactly( + User.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .avatarUrl("avatar_url") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .email("email") + .familyName("family_name") + .givenName("given_name") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val userListPageResponse = + UserListPageResponse.builder() + .addObject( + User.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .avatarUrl("avatar_url") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .email("email") + .familyName("family_name") + .givenName("given_name") + .build() + ) + .build() + + val roundtrippedUserListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(userListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedUserListPageResponse).isEqualTo(userListPageResponse) + } +} diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewListPageResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewListPageResponseTest.kt new file mode 100644 index 00000000..9f6575f0 --- /dev/null +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/models/ViewListPageResponseTest.kt @@ -0,0 +1,164 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.models + +import com.braintrustdata.api.core.JsonValue +import com.braintrustdata.api.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ViewListPageResponseTest { + + @Test + fun create() { + val viewListPageResponse = + ViewListPageResponse.builder() + .addObject( + View.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(AclObjectType.ORGANIZATION) + .viewType(View.ViewType.PROJECTS) + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .options( + ViewOptions.builder() + .addColumnOrder("string") + .columnSizing( + ViewOptions.ColumnSizing.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .columnVisibility( + ViewOptions.ColumnVisibility.builder() + .putAdditionalProperty("foo", JsonValue.from(true)) + .build() + ) + .grouping("grouping") + .layout("layout") + .rowHeight("rowHeight") + .build() + ) + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .viewData( + ViewData.builder() + .search( + ViewDataSearch.builder() + .addFilter(JsonValue.from(mapOf())) + .addMatch(JsonValue.from(mapOf())) + .addSort(JsonValue.from(mapOf())) + .addTag(JsonValue.from(mapOf())) + .build() + ) + .build() + ) + .build() + ) + .build() + + assertThat(viewListPageResponse.objects()) + .containsExactly( + View.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(AclObjectType.ORGANIZATION) + .viewType(View.ViewType.PROJECTS) + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .options( + ViewOptions.builder() + .addColumnOrder("string") + .columnSizing( + ViewOptions.ColumnSizing.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .columnVisibility( + ViewOptions.ColumnVisibility.builder() + .putAdditionalProperty("foo", JsonValue.from(true)) + .build() + ) + .grouping("grouping") + .layout("layout") + .rowHeight("rowHeight") + .build() + ) + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .viewData( + ViewData.builder() + .search( + ViewDataSearch.builder() + .addFilter(JsonValue.from(mapOf())) + .addMatch(JsonValue.from(mapOf())) + .addSort(JsonValue.from(mapOf())) + .addTag(JsonValue.from(mapOf())) + .build() + ) + .build() + ) + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val viewListPageResponse = + ViewListPageResponse.builder() + .addObject( + View.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .objectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .objectType(AclObjectType.ORGANIZATION) + .viewType(View.ViewType.PROJECTS) + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .options( + ViewOptions.builder() + .addColumnOrder("string") + .columnSizing( + ViewOptions.ColumnSizing.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .columnVisibility( + ViewOptions.ColumnVisibility.builder() + .putAdditionalProperty("foo", JsonValue.from(true)) + .build() + ) + .grouping("grouping") + .layout("layout") + .rowHeight("rowHeight") + .build() + ) + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .viewData( + ViewData.builder() + .search( + ViewDataSearch.builder() + .addFilter(JsonValue.from(mapOf())) + .addMatch(JsonValue.from(mapOf())) + .addSort(JsonValue.from(mapOf())) + .addTag(JsonValue.from(mapOf())) + .build() + ) + .build() + ) + .build() + ) + .build() + + val roundtrippedViewListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(viewListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedViewListPageResponse).isEqualTo(viewListPageResponse) + } +} From b61888c0b3080b0ed42f8179a9fc772333cb0d9c Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 10 Apr 2025 04:39:19 +0000 Subject: [PATCH 34/42] refactor(client): migrate pages to builder pattern --- .../braintrustdata/api/models/AclListPage.kt | 106 +++++++++++----- .../api/models/AclListPageAsync.kt | 110 ++++++++++++----- .../api/models/AiSecretListPage.kt | 110 ++++++++++++----- .../api/models/AiSecretListPageAsync.kt | 113 +++++++++++++----- .../api/models/ApiKeyListPage.kt | 109 ++++++++++++----- .../api/models/ApiKeyListPageAsync.kt | 113 +++++++++++++----- .../api/models/DatasetListPage.kt | 110 ++++++++++++----- .../api/models/DatasetListPageAsync.kt | 113 +++++++++++++----- .../api/models/ExperimentListPage.kt | 110 ++++++++++++----- .../api/models/ExperimentListPageAsync.kt | 113 +++++++++++++----- .../api/models/FunctionListPage.kt | 110 ++++++++++++----- .../api/models/FunctionListPageAsync.kt | 113 +++++++++++++----- .../api/models/GroupListPage.kt | 109 ++++++++++++----- .../api/models/GroupListPageAsync.kt | 113 +++++++++++++----- .../api/models/OrganizationListPage.kt | 110 ++++++++++++----- .../api/models/OrganizationListPageAsync.kt | 113 +++++++++++++----- .../api/models/ProjectListPage.kt | 110 ++++++++++++----- .../api/models/ProjectListPageAsync.kt | 113 +++++++++++++----- .../api/models/ProjectScoreListPage.kt | 110 ++++++++++++----- .../api/models/ProjectScoreListPageAsync.kt | 113 +++++++++++++----- .../api/models/ProjectTagListPage.kt | 110 ++++++++++++----- .../api/models/ProjectTagListPageAsync.kt | 113 +++++++++++++----- .../api/models/PromptListPage.kt | 109 ++++++++++++----- .../api/models/PromptListPageAsync.kt | 113 +++++++++++++----- .../braintrustdata/api/models/RoleListPage.kt | 106 +++++++++++----- .../api/models/RoleListPageAsync.kt | 113 +++++++++++++----- .../api/models/SpanIframeListPage.kt | 110 ++++++++++++----- .../api/models/SpanIframeListPageAsync.kt | 113 +++++++++++++----- .../braintrustdata/api/models/UserListPage.kt | 106 +++++++++++----- .../api/models/UserListPageAsync.kt | 113 +++++++++++++----- .../braintrustdata/api/models/ViewListPage.kt | 106 +++++++++++----- .../api/models/ViewListPageAsync.kt | 113 +++++++++++++----- .../api/services/async/AclServiceAsyncImpl.kt | 6 +- .../async/AiSecretServiceAsyncImpl.kt | 10 +- .../services/async/ApiKeyServiceAsyncImpl.kt | 10 +- .../services/async/DatasetServiceAsyncImpl.kt | 10 +- .../async/ExperimentServiceAsyncImpl.kt | 10 +- .../async/FunctionServiceAsyncImpl.kt | 10 +- .../services/async/GroupServiceAsyncImpl.kt | 10 +- .../async/OrganizationServiceAsyncImpl.kt | 10 +- .../async/ProjectScoreServiceAsyncImpl.kt | 10 +- .../services/async/ProjectServiceAsyncImpl.kt | 10 +- .../async/ProjectTagServiceAsyncImpl.kt | 10 +- .../services/async/PromptServiceAsyncImpl.kt | 10 +- .../services/async/RoleServiceAsyncImpl.kt | 10 +- .../async/SpanIframeServiceAsyncImpl.kt | 10 +- .../services/async/UserServiceAsyncImpl.kt | 10 +- .../services/async/ViewServiceAsyncImpl.kt | 10 +- .../api/services/blocking/AclServiceImpl.kt | 8 +- .../services/blocking/AiSecretServiceImpl.kt | 8 +- .../services/blocking/ApiKeyServiceImpl.kt | 8 +- .../services/blocking/DatasetServiceImpl.kt | 8 +- .../blocking/ExperimentServiceImpl.kt | 8 +- .../services/blocking/FunctionServiceImpl.kt | 8 +- .../api/services/blocking/GroupServiceImpl.kt | 8 +- .../blocking/OrganizationServiceImpl.kt | 6 +- .../blocking/ProjectScoreServiceImpl.kt | 6 +- .../services/blocking/ProjectServiceImpl.kt | 8 +- .../blocking/ProjectTagServiceImpl.kt | 8 +- .../services/blocking/PromptServiceImpl.kt | 8 +- .../api/services/blocking/RoleServiceImpl.kt | 8 +- .../blocking/SpanIframeServiceImpl.kt | 8 +- .../api/services/blocking/UserServiceImpl.kt | 8 +- .../api/services/blocking/ViewServiceImpl.kt | 8 +- 64 files changed, 2773 insertions(+), 1053 deletions(-) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt index 08254621..fd5ac29d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.AclService import java.util.Objects import java.util.Optional @@ -9,20 +10,14 @@ import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * List out all acls. The acls are sorted by creation date, with the most recently-created acls - * coming first - */ +/** @see [AclService.list] */ class AclListPage private constructor( - private val aclsService: AclService, + private val service: AclService, private val params: AclListParams, private val response: AclListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): AclListPageResponse = response - /** * Delegates to [AclListPageResponse], but gracefully handles missing data. * @@ -30,19 +25,6 @@ private constructor( */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is AclListPage && aclsService == other.aclsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(aclsService, params, response) /* spotless:on */ - - override fun toString() = - "AclListPage{aclsService=$aclsService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -59,17 +41,75 @@ private constructor( ) } - fun getNextPage(): Optional { - return getNextPageParams().map { aclsService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): AclListParams = params + + /** The response that this page was parsed from. */ + fun response(): AclListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of(aclsService: AclService, params: AclListParams, response: AclListPageResponse) = - AclListPage(aclsService, params, response) + /** + * Returns a mutable builder for constructing an instance of [AclListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AclListPage]. */ + class Builder internal constructor() { + + private var service: AclService? = null + private var params: AclListParams? = null + private var response: AclListPageResponse? = null + + @JvmSynthetic + internal fun from(aclListPage: AclListPage) = apply { + service = aclListPage.service + params = aclListPage.params + response = aclListPage.response + } + + fun service(service: AclService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: AclListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: AclListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [AclListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AclListPage = + AclListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: AclListPage) : Iterable { @@ -90,4 +130,16 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is AclListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = "AclListPage{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt index e2491ba1..20160da8 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.AclServiceAsync import java.util.Objects import java.util.Optional @@ -10,20 +11,14 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * List out all acls. The acls are sorted by creation date, with the most recently-created acls - * coming first - */ +/** @see [AclServiceAsync.list] */ class AclListPageAsync private constructor( - private val aclsService: AclServiceAsync, + private val service: AclServiceAsync, private val params: AclListParams, private val response: AclListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): AclListPageResponse = response - /** * Delegates to [AclListPageResponse], but gracefully handles missing data. * @@ -31,19 +26,6 @@ private constructor( */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is AclListPageAsync && aclsService == other.aclsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(aclsService, params, response) /* spotless:on */ - - override fun toString() = - "AclListPageAsync{aclsService=$aclsService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -60,19 +42,78 @@ private constructor( ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { aclsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): AclListParams = params + + /** The response that this page was parsed from. */ + fun response(): AclListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of(aclsService: AclServiceAsync, params: AclListParams, response: AclListPageResponse) = - AclListPageAsync(aclsService, params, response) + /** + * Returns a mutable builder for constructing an instance of [AclListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AclListPageAsync]. */ + class Builder internal constructor() { + + private var service: AclServiceAsync? = null + private var params: AclListParams? = null + private var response: AclListPageResponse? = null + + @JvmSynthetic + internal fun from(aclListPageAsync: AclListPageAsync) = apply { + service = aclListPageAsync.service + params = aclListPageAsync.params + response = aclListPageAsync.response + } + + fun service(service: AclServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: AclListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: AclListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [AclListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AclListPageAsync = + AclListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: AclListPageAsync) { @@ -100,4 +141,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is AclListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "AclListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt index 620e441e..021f2341 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.AiSecretService import java.util.Objects import java.util.Optional @@ -9,20 +10,14 @@ import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * List out all ai_secrets. The ai_secrets are sorted by creation date, with the most - * recently-created ai_secrets coming first - */ +/** @see [AiSecretService.list] */ class AiSecretListPage private constructor( - private val aiSecretsService: AiSecretService, + private val service: AiSecretService, private val params: AiSecretListParams, private val response: AiSecretListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): AiSecretListPageResponse = response - /** * Delegates to [AiSecretListPageResponse], but gracefully handles missing data. * @@ -31,19 +26,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is AiSecretListPage && aiSecretsService == other.aiSecretsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(aiSecretsService, params, response) /* spotless:on */ - - override fun toString() = - "AiSecretListPage{aiSecretsService=$aiSecretsService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -60,20 +42,75 @@ private constructor( ) } - fun getNextPage(): Optional { - return getNextPageParams().map { aiSecretsService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): AiSecretListParams = params + + /** The response that this page was parsed from. */ + fun response(): AiSecretListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - aiSecretsService: AiSecretService, - params: AiSecretListParams, - response: AiSecretListPageResponse, - ) = AiSecretListPage(aiSecretsService, params, response) + /** + * Returns a mutable builder for constructing an instance of [AiSecretListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AiSecretListPage]. */ + class Builder internal constructor() { + + private var service: AiSecretService? = null + private var params: AiSecretListParams? = null + private var response: AiSecretListPageResponse? = null + + @JvmSynthetic + internal fun from(aiSecretListPage: AiSecretListPage) = apply { + service = aiSecretListPage.service + params = aiSecretListPage.params + response = aiSecretListPage.response + } + + fun service(service: AiSecretService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: AiSecretListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: AiSecretListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [AiSecretListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AiSecretListPage = + AiSecretListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: AiSecretListPage) : Iterable { @@ -94,4 +131,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is AiSecretListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "AiSecretListPage{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt index a81fec2f..597dd9cd 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.AiSecretServiceAsync import java.util.Objects import java.util.Optional @@ -10,20 +11,14 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * List out all ai_secrets. The ai_secrets are sorted by creation date, with the most - * recently-created ai_secrets coming first - */ +/** @see [AiSecretServiceAsync.list] */ class AiSecretListPageAsync private constructor( - private val aiSecretsService: AiSecretServiceAsync, + private val service: AiSecretServiceAsync, private val params: AiSecretListParams, private val response: AiSecretListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): AiSecretListPageResponse = response - /** * Delegates to [AiSecretListPageResponse], but gracefully handles missing data. * @@ -32,19 +27,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is AiSecretListPageAsync && aiSecretsService == other.aiSecretsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(aiSecretsService, params, response) /* spotless:on */ - - override fun toString() = - "AiSecretListPageAsync{aiSecretsService=$aiSecretsService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -61,22 +43,78 @@ private constructor( ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { aiSecretsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): AiSecretListParams = params + + /** The response that this page was parsed from. */ + fun response(): AiSecretListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - aiSecretsService: AiSecretServiceAsync, - params: AiSecretListParams, - response: AiSecretListPageResponse, - ) = AiSecretListPageAsync(aiSecretsService, params, response) + /** + * Returns a mutable builder for constructing an instance of [AiSecretListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AiSecretListPageAsync]. */ + class Builder internal constructor() { + + private var service: AiSecretServiceAsync? = null + private var params: AiSecretListParams? = null + private var response: AiSecretListPageResponse? = null + + @JvmSynthetic + internal fun from(aiSecretListPageAsync: AiSecretListPageAsync) = apply { + service = aiSecretListPageAsync.service + params = aiSecretListPageAsync.params + response = aiSecretListPageAsync.response + } + + fun service(service: AiSecretServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: AiSecretListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: AiSecretListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [AiSecretListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AiSecretListPageAsync = + AiSecretListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: AiSecretListPageAsync) { @@ -104,4 +142,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is AiSecretListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "AiSecretListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt index 9947a7ff..0aeea56f 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.ApiKeyService import java.util.Objects import java.util.Optional @@ -9,20 +10,14 @@ import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * List out all api_keys. The api_keys are sorted by creation date, with the most recently-created - * api_keys coming first - */ +/** @see [ApiKeyService.list] */ class ApiKeyListPage private constructor( - private val apiKeysService: ApiKeyService, + private val service: ApiKeyService, private val params: ApiKeyListParams, private val response: ApiKeyListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): ApiKeyListPageResponse = response - /** * Delegates to [ApiKeyListPageResponse], but gracefully handles missing data. * @@ -31,19 +26,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ApiKeyListPage && apiKeysService == other.apiKeysService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(apiKeysService, params, response) /* spotless:on */ - - override fun toString() = - "ApiKeyListPage{apiKeysService=$apiKeysService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -60,20 +42,75 @@ private constructor( ) } - fun getNextPage(): Optional { - return getNextPageParams().map { apiKeysService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): ApiKeyListParams = params + + /** The response that this page was parsed from. */ + fun response(): ApiKeyListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - apiKeysService: ApiKeyService, - params: ApiKeyListParams, - response: ApiKeyListPageResponse, - ) = ApiKeyListPage(apiKeysService, params, response) + /** + * Returns a mutable builder for constructing an instance of [ApiKeyListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ApiKeyListPage]. */ + class Builder internal constructor() { + + private var service: ApiKeyService? = null + private var params: ApiKeyListParams? = null + private var response: ApiKeyListPageResponse? = null + + @JvmSynthetic + internal fun from(apiKeyListPage: ApiKeyListPage) = apply { + service = apiKeyListPage.service + params = apiKeyListPage.params + response = apiKeyListPage.response + } + + fun service(service: ApiKeyService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: ApiKeyListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ApiKeyListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [ApiKeyListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ApiKeyListPage = + ApiKeyListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: ApiKeyListPage) : Iterable { @@ -94,4 +131,16 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ApiKeyListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = "ApiKeyListPage{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt index 4b756792..5bc2cbe9 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.ApiKeyServiceAsync import java.util.Objects import java.util.Optional @@ -10,20 +11,14 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * List out all api_keys. The api_keys are sorted by creation date, with the most recently-created - * api_keys coming first - */ +/** @see [ApiKeyServiceAsync.list] */ class ApiKeyListPageAsync private constructor( - private val apiKeysService: ApiKeyServiceAsync, + private val service: ApiKeyServiceAsync, private val params: ApiKeyListParams, private val response: ApiKeyListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): ApiKeyListPageResponse = response - /** * Delegates to [ApiKeyListPageResponse], but gracefully handles missing data. * @@ -32,19 +27,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ApiKeyListPageAsync && apiKeysService == other.apiKeysService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(apiKeysService, params, response) /* spotless:on */ - - override fun toString() = - "ApiKeyListPageAsync{apiKeysService=$apiKeysService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -61,22 +43,78 @@ private constructor( ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { apiKeysService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): ApiKeyListParams = params + + /** The response that this page was parsed from. */ + fun response(): ApiKeyListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - apiKeysService: ApiKeyServiceAsync, - params: ApiKeyListParams, - response: ApiKeyListPageResponse, - ) = ApiKeyListPageAsync(apiKeysService, params, response) + /** + * Returns a mutable builder for constructing an instance of [ApiKeyListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ApiKeyListPageAsync]. */ + class Builder internal constructor() { + + private var service: ApiKeyServiceAsync? = null + private var params: ApiKeyListParams? = null + private var response: ApiKeyListPageResponse? = null + + @JvmSynthetic + internal fun from(apiKeyListPageAsync: ApiKeyListPageAsync) = apply { + service = apiKeyListPageAsync.service + params = apiKeyListPageAsync.params + response = apiKeyListPageAsync.response + } + + fun service(service: ApiKeyServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: ApiKeyListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ApiKeyListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [ApiKeyListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ApiKeyListPageAsync = + ApiKeyListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: ApiKeyListPageAsync) { @@ -104,4 +142,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ApiKeyListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "ApiKeyListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt index a1fb69d0..9e96f20b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.DatasetService import java.util.Objects import java.util.Optional @@ -9,20 +10,14 @@ import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * List out all datasets. The datasets are sorted by creation date, with the most recently-created - * datasets coming first - */ +/** @see [DatasetService.list] */ class DatasetListPage private constructor( - private val datasetsService: DatasetService, + private val service: DatasetService, private val params: DatasetListParams, private val response: DatasetListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): DatasetListPageResponse = response - /** * Delegates to [DatasetListPageResponse], but gracefully handles missing data. * @@ -31,19 +26,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is DatasetListPage && datasetsService == other.datasetsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(datasetsService, params, response) /* spotless:on */ - - override fun toString() = - "DatasetListPage{datasetsService=$datasetsService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -60,20 +42,75 @@ private constructor( ) } - fun getNextPage(): Optional { - return getNextPageParams().map { datasetsService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): DatasetListParams = params + + /** The response that this page was parsed from. */ + fun response(): DatasetListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - datasetsService: DatasetService, - params: DatasetListParams, - response: DatasetListPageResponse, - ) = DatasetListPage(datasetsService, params, response) + /** + * Returns a mutable builder for constructing an instance of [DatasetListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [DatasetListPage]. */ + class Builder internal constructor() { + + private var service: DatasetService? = null + private var params: DatasetListParams? = null + private var response: DatasetListPageResponse? = null + + @JvmSynthetic + internal fun from(datasetListPage: DatasetListPage) = apply { + service = datasetListPage.service + params = datasetListPage.params + response = datasetListPage.response + } + + fun service(service: DatasetService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: DatasetListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: DatasetListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [DatasetListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): DatasetListPage = + DatasetListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: DatasetListPage) : Iterable { @@ -94,4 +131,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is DatasetListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "DatasetListPage{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt index 85a26a5f..c7e230c8 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.DatasetServiceAsync import java.util.Objects import java.util.Optional @@ -10,20 +11,14 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * List out all datasets. The datasets are sorted by creation date, with the most recently-created - * datasets coming first - */ +/** @see [DatasetServiceAsync.list] */ class DatasetListPageAsync private constructor( - private val datasetsService: DatasetServiceAsync, + private val service: DatasetServiceAsync, private val params: DatasetListParams, private val response: DatasetListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): DatasetListPageResponse = response - /** * Delegates to [DatasetListPageResponse], but gracefully handles missing data. * @@ -32,19 +27,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is DatasetListPageAsync && datasetsService == other.datasetsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(datasetsService, params, response) /* spotless:on */ - - override fun toString() = - "DatasetListPageAsync{datasetsService=$datasetsService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -61,22 +43,78 @@ private constructor( ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { datasetsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): DatasetListParams = params + + /** The response that this page was parsed from. */ + fun response(): DatasetListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - datasetsService: DatasetServiceAsync, - params: DatasetListParams, - response: DatasetListPageResponse, - ) = DatasetListPageAsync(datasetsService, params, response) + /** + * Returns a mutable builder for constructing an instance of [DatasetListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [DatasetListPageAsync]. */ + class Builder internal constructor() { + + private var service: DatasetServiceAsync? = null + private var params: DatasetListParams? = null + private var response: DatasetListPageResponse? = null + + @JvmSynthetic + internal fun from(datasetListPageAsync: DatasetListPageAsync) = apply { + service = datasetListPageAsync.service + params = datasetListPageAsync.params + response = datasetListPageAsync.response + } + + fun service(service: DatasetServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: DatasetListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: DatasetListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [DatasetListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): DatasetListPageAsync = + DatasetListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: DatasetListPageAsync) { @@ -104,4 +142,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is DatasetListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "DatasetListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt index d31124c0..64e38158 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.ExperimentService import java.util.Objects import java.util.Optional @@ -9,20 +10,14 @@ import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * List out all experiments. The experiments are sorted by creation date, with the most - * recently-created experiments coming first - */ +/** @see [ExperimentService.list] */ class ExperimentListPage private constructor( - private val experimentsService: ExperimentService, + private val service: ExperimentService, private val params: ExperimentListParams, private val response: ExperimentListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): ExperimentListPageResponse = response - /** * Delegates to [ExperimentListPageResponse], but gracefully handles missing data. * @@ -31,19 +26,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ExperimentListPage && experimentsService == other.experimentsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(experimentsService, params, response) /* spotless:on */ - - override fun toString() = - "ExperimentListPage{experimentsService=$experimentsService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -60,20 +42,75 @@ private constructor( ) } - fun getNextPage(): Optional { - return getNextPageParams().map { experimentsService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): ExperimentListParams = params + + /** The response that this page was parsed from. */ + fun response(): ExperimentListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - experimentsService: ExperimentService, - params: ExperimentListParams, - response: ExperimentListPageResponse, - ) = ExperimentListPage(experimentsService, params, response) + /** + * Returns a mutable builder for constructing an instance of [ExperimentListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ExperimentListPage]. */ + class Builder internal constructor() { + + private var service: ExperimentService? = null + private var params: ExperimentListParams? = null + private var response: ExperimentListPageResponse? = null + + @JvmSynthetic + internal fun from(experimentListPage: ExperimentListPage) = apply { + service = experimentListPage.service + params = experimentListPage.params + response = experimentListPage.response + } + + fun service(service: ExperimentService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: ExperimentListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ExperimentListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [ExperimentListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ExperimentListPage = + ExperimentListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: ExperimentListPage) : Iterable { @@ -94,4 +131,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ExperimentListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "ExperimentListPage{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt index 72766718..b8b5c33d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.ExperimentServiceAsync import java.util.Objects import java.util.Optional @@ -10,20 +11,14 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * List out all experiments. The experiments are sorted by creation date, with the most - * recently-created experiments coming first - */ +/** @see [ExperimentServiceAsync.list] */ class ExperimentListPageAsync private constructor( - private val experimentsService: ExperimentServiceAsync, + private val service: ExperimentServiceAsync, private val params: ExperimentListParams, private val response: ExperimentListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): ExperimentListPageResponse = response - /** * Delegates to [ExperimentListPageResponse], but gracefully handles missing data. * @@ -32,19 +27,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ExperimentListPageAsync && experimentsService == other.experimentsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(experimentsService, params, response) /* spotless:on */ - - override fun toString() = - "ExperimentListPageAsync{experimentsService=$experimentsService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -61,22 +43,78 @@ private constructor( ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { experimentsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): ExperimentListParams = params + + /** The response that this page was parsed from. */ + fun response(): ExperimentListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - experimentsService: ExperimentServiceAsync, - params: ExperimentListParams, - response: ExperimentListPageResponse, - ) = ExperimentListPageAsync(experimentsService, params, response) + /** + * Returns a mutable builder for constructing an instance of [ExperimentListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ExperimentListPageAsync]. */ + class Builder internal constructor() { + + private var service: ExperimentServiceAsync? = null + private var params: ExperimentListParams? = null + private var response: ExperimentListPageResponse? = null + + @JvmSynthetic + internal fun from(experimentListPageAsync: ExperimentListPageAsync) = apply { + service = experimentListPageAsync.service + params = experimentListPageAsync.params + response = experimentListPageAsync.response + } + + fun service(service: ExperimentServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: ExperimentListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ExperimentListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [ExperimentListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ExperimentListPageAsync = + ExperimentListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: ExperimentListPageAsync) { @@ -104,4 +142,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ExperimentListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "ExperimentListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPage.kt index 785f5713..26550ec2 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPage.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.FunctionService import java.util.Objects import java.util.Optional @@ -9,20 +10,14 @@ import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * List out all functions. The functions are sorted by creation date, with the most recently-created - * functions coming first - */ +/** @see [FunctionService.list] */ class FunctionListPage private constructor( - private val functionsService: FunctionService, + private val service: FunctionService, private val params: FunctionListParams, private val response: FunctionListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): FunctionListPageResponse = response - /** * Delegates to [FunctionListPageResponse], but gracefully handles missing data. * @@ -31,19 +26,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is FunctionListPage && functionsService == other.functionsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(functionsService, params, response) /* spotless:on */ - - override fun toString() = - "FunctionListPage{functionsService=$functionsService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -60,20 +42,75 @@ private constructor( ) } - fun getNextPage(): Optional { - return getNextPageParams().map { functionsService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): FunctionListParams = params + + /** The response that this page was parsed from. */ + fun response(): FunctionListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - functionsService: FunctionService, - params: FunctionListParams, - response: FunctionListPageResponse, - ) = FunctionListPage(functionsService, params, response) + /** + * Returns a mutable builder for constructing an instance of [FunctionListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [FunctionListPage]. */ + class Builder internal constructor() { + + private var service: FunctionService? = null + private var params: FunctionListParams? = null + private var response: FunctionListPageResponse? = null + + @JvmSynthetic + internal fun from(functionListPage: FunctionListPage) = apply { + service = functionListPage.service + params = functionListPage.params + response = functionListPage.response + } + + fun service(service: FunctionService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: FunctionListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: FunctionListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [FunctionListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): FunctionListPage = + FunctionListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: FunctionListPage) : Iterable { @@ -94,4 +131,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FunctionListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "FunctionListPage{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageAsync.kt index 5f2f641f..77b7c749 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.FunctionServiceAsync import java.util.Objects import java.util.Optional @@ -10,20 +11,14 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * List out all functions. The functions are sorted by creation date, with the most recently-created - * functions coming first - */ +/** @see [FunctionServiceAsync.list] */ class FunctionListPageAsync private constructor( - private val functionsService: FunctionServiceAsync, + private val service: FunctionServiceAsync, private val params: FunctionListParams, private val response: FunctionListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): FunctionListPageResponse = response - /** * Delegates to [FunctionListPageResponse], but gracefully handles missing data. * @@ -32,19 +27,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is FunctionListPageAsync && functionsService == other.functionsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(functionsService, params, response) /* spotless:on */ - - override fun toString() = - "FunctionListPageAsync{functionsService=$functionsService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -61,22 +43,78 @@ private constructor( ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { functionsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): FunctionListParams = params + + /** The response that this page was parsed from. */ + fun response(): FunctionListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - functionsService: FunctionServiceAsync, - params: FunctionListParams, - response: FunctionListPageResponse, - ) = FunctionListPageAsync(functionsService, params, response) + /** + * Returns a mutable builder for constructing an instance of [FunctionListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [FunctionListPageAsync]. */ + class Builder internal constructor() { + + private var service: FunctionServiceAsync? = null + private var params: FunctionListParams? = null + private var response: FunctionListPageResponse? = null + + @JvmSynthetic + internal fun from(functionListPageAsync: FunctionListPageAsync) = apply { + service = functionListPageAsync.service + params = functionListPageAsync.params + response = functionListPageAsync.response + } + + fun service(service: FunctionServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: FunctionListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: FunctionListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [FunctionListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): FunctionListPageAsync = + FunctionListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: FunctionListPageAsync) { @@ -104,4 +142,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FunctionListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "FunctionListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt index 440a7ad4..af4e384c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.GroupService import java.util.Objects import java.util.Optional @@ -9,20 +10,14 @@ import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * List out all groups. The groups are sorted by creation date, with the most recently-created - * groups coming first - */ +/** @see [GroupService.list] */ class GroupListPage private constructor( - private val groupsService: GroupService, + private val service: GroupService, private val params: GroupListParams, private val response: GroupListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): GroupListPageResponse = response - /** * Delegates to [GroupListPageResponse], but gracefully handles missing data. * @@ -31,19 +26,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is GroupListPage && groupsService == other.groupsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(groupsService, params, response) /* spotless:on */ - - override fun toString() = - "GroupListPage{groupsService=$groupsService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -60,20 +42,75 @@ private constructor( ) } - fun getNextPage(): Optional { - return getNextPageParams().map { groupsService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): GroupListParams = params + + /** The response that this page was parsed from. */ + fun response(): GroupListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - groupsService: GroupService, - params: GroupListParams, - response: GroupListPageResponse, - ) = GroupListPage(groupsService, params, response) + /** + * Returns a mutable builder for constructing an instance of [GroupListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [GroupListPage]. */ + class Builder internal constructor() { + + private var service: GroupService? = null + private var params: GroupListParams? = null + private var response: GroupListPageResponse? = null + + @JvmSynthetic + internal fun from(groupListPage: GroupListPage) = apply { + service = groupListPage.service + params = groupListPage.params + response = groupListPage.response + } + + fun service(service: GroupService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: GroupListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: GroupListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [GroupListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupListPage = + GroupListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: GroupListPage) : Iterable { @@ -94,4 +131,16 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is GroupListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = "GroupListPage{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt index 74a130f3..57388a7d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.GroupServiceAsync import java.util.Objects import java.util.Optional @@ -10,20 +11,14 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * List out all groups. The groups are sorted by creation date, with the most recently-created - * groups coming first - */ +/** @see [GroupServiceAsync.list] */ class GroupListPageAsync private constructor( - private val groupsService: GroupServiceAsync, + private val service: GroupServiceAsync, private val params: GroupListParams, private val response: GroupListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): GroupListPageResponse = response - /** * Delegates to [GroupListPageResponse], but gracefully handles missing data. * @@ -32,19 +27,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is GroupListPageAsync && groupsService == other.groupsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(groupsService, params, response) /* spotless:on */ - - override fun toString() = - "GroupListPageAsync{groupsService=$groupsService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -61,22 +43,78 @@ private constructor( ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { groupsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): GroupListParams = params + + /** The response that this page was parsed from. */ + fun response(): GroupListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - groupsService: GroupServiceAsync, - params: GroupListParams, - response: GroupListPageResponse, - ) = GroupListPageAsync(groupsService, params, response) + /** + * Returns a mutable builder for constructing an instance of [GroupListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [GroupListPageAsync]. */ + class Builder internal constructor() { + + private var service: GroupServiceAsync? = null + private var params: GroupListParams? = null + private var response: GroupListPageResponse? = null + + @JvmSynthetic + internal fun from(groupListPageAsync: GroupListPageAsync) = apply { + service = groupListPageAsync.service + params = groupListPageAsync.params + response = groupListPageAsync.response + } + + fun service(service: GroupServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: GroupListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: GroupListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [GroupListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupListPageAsync = + GroupListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: GroupListPageAsync) { @@ -104,4 +142,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is GroupListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "GroupListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt index 28301816..f8d68211 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.OrganizationService import java.util.Objects import java.util.Optional @@ -9,20 +10,14 @@ import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * List out all organizations. The organizations are sorted by creation date, with the most - * recently-created organizations coming first - */ +/** @see [OrganizationService.list] */ class OrganizationListPage private constructor( - private val organizationsService: OrganizationService, + private val service: OrganizationService, private val params: OrganizationListParams, private val response: OrganizationListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): OrganizationListPageResponse = response - /** * Delegates to [OrganizationListPageResponse], but gracefully handles missing data. * @@ -31,19 +26,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is OrganizationListPage && organizationsService == other.organizationsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(organizationsService, params, response) /* spotless:on */ - - override fun toString() = - "OrganizationListPage{organizationsService=$organizationsService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -60,20 +42,75 @@ private constructor( ) } - fun getNextPage(): Optional { - return getNextPageParams().map { organizationsService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): OrganizationListParams = params + + /** The response that this page was parsed from. */ + fun response(): OrganizationListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - organizationsService: OrganizationService, - params: OrganizationListParams, - response: OrganizationListPageResponse, - ) = OrganizationListPage(organizationsService, params, response) + /** + * Returns a mutable builder for constructing an instance of [OrganizationListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationListPage]. */ + class Builder internal constructor() { + + private var service: OrganizationService? = null + private var params: OrganizationListParams? = null + private var response: OrganizationListPageResponse? = null + + @JvmSynthetic + internal fun from(organizationListPage: OrganizationListPage) = apply { + service = organizationListPage.service + params = organizationListPage.params + response = organizationListPage.response + } + + fun service(service: OrganizationService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: OrganizationListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: OrganizationListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [OrganizationListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationListPage = + OrganizationListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: OrganizationListPage) : Iterable { @@ -94,4 +131,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is OrganizationListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "OrganizationListPage{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt index 02e8363c..8d1fb8a2 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.OrganizationServiceAsync import java.util.Objects import java.util.Optional @@ -10,20 +11,14 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * List out all organizations. The organizations are sorted by creation date, with the most - * recently-created organizations coming first - */ +/** @see [OrganizationServiceAsync.list] */ class OrganizationListPageAsync private constructor( - private val organizationsService: OrganizationServiceAsync, + private val service: OrganizationServiceAsync, private val params: OrganizationListParams, private val response: OrganizationListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): OrganizationListPageResponse = response - /** * Delegates to [OrganizationListPageResponse], but gracefully handles missing data. * @@ -32,19 +27,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is OrganizationListPageAsync && organizationsService == other.organizationsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(organizationsService, params, response) /* spotless:on */ - - override fun toString() = - "OrganizationListPageAsync{organizationsService=$organizationsService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -61,22 +43,78 @@ private constructor( ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { organizationsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): OrganizationListParams = params + + /** The response that this page was parsed from. */ + fun response(): OrganizationListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - organizationsService: OrganizationServiceAsync, - params: OrganizationListParams, - response: OrganizationListPageResponse, - ) = OrganizationListPageAsync(organizationsService, params, response) + /** + * Returns a mutable builder for constructing an instance of [OrganizationListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OrganizationListPageAsync]. */ + class Builder internal constructor() { + + private var service: OrganizationServiceAsync? = null + private var params: OrganizationListParams? = null + private var response: OrganizationListPageResponse? = null + + @JvmSynthetic + internal fun from(organizationListPageAsync: OrganizationListPageAsync) = apply { + service = organizationListPageAsync.service + params = organizationListPageAsync.params + response = organizationListPageAsync.response + } + + fun service(service: OrganizationServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: OrganizationListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: OrganizationListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [OrganizationListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OrganizationListPageAsync = + OrganizationListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: OrganizationListPageAsync) { @@ -104,4 +142,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is OrganizationListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "OrganizationListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPage.kt index 9e74375f..0ed7293d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPage.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.ProjectService import java.util.Objects import java.util.Optional @@ -9,20 +10,14 @@ import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * List out all projects. The projects are sorted by creation date, with the most recently-created - * projects coming first - */ +/** @see [ProjectService.list] */ class ProjectListPage private constructor( - private val projectsService: ProjectService, + private val service: ProjectService, private val params: ProjectListParams, private val response: ProjectListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): ProjectListPageResponse = response - /** * Delegates to [ProjectListPageResponse], but gracefully handles missing data. * @@ -31,19 +26,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ProjectListPage && projectsService == other.projectsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(projectsService, params, response) /* spotless:on */ - - override fun toString() = - "ProjectListPage{projectsService=$projectsService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -60,20 +42,75 @@ private constructor( ) } - fun getNextPage(): Optional { - return getNextPageParams().map { projectsService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): ProjectListParams = params + + /** The response that this page was parsed from. */ + fun response(): ProjectListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - projectsService: ProjectService, - params: ProjectListParams, - response: ProjectListPageResponse, - ) = ProjectListPage(projectsService, params, response) + /** + * Returns a mutable builder for constructing an instance of [ProjectListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProjectListPage]. */ + class Builder internal constructor() { + + private var service: ProjectService? = null + private var params: ProjectListParams? = null + private var response: ProjectListPageResponse? = null + + @JvmSynthetic + internal fun from(projectListPage: ProjectListPage) = apply { + service = projectListPage.service + params = projectListPage.params + response = projectListPage.response + } + + fun service(service: ProjectService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: ProjectListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ProjectListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [ProjectListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProjectListPage = + ProjectListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: ProjectListPage) : Iterable { @@ -94,4 +131,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ProjectListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "ProjectListPage{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageAsync.kt index fbb36339..3051a64a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.ProjectServiceAsync import java.util.Objects import java.util.Optional @@ -10,20 +11,14 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * List out all projects. The projects are sorted by creation date, with the most recently-created - * projects coming first - */ +/** @see [ProjectServiceAsync.list] */ class ProjectListPageAsync private constructor( - private val projectsService: ProjectServiceAsync, + private val service: ProjectServiceAsync, private val params: ProjectListParams, private val response: ProjectListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): ProjectListPageResponse = response - /** * Delegates to [ProjectListPageResponse], but gracefully handles missing data. * @@ -32,19 +27,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ProjectListPageAsync && projectsService == other.projectsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(projectsService, params, response) /* spotless:on */ - - override fun toString() = - "ProjectListPageAsync{projectsService=$projectsService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -61,22 +43,78 @@ private constructor( ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { projectsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): ProjectListParams = params + + /** The response that this page was parsed from. */ + fun response(): ProjectListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - projectsService: ProjectServiceAsync, - params: ProjectListParams, - response: ProjectListPageResponse, - ) = ProjectListPageAsync(projectsService, params, response) + /** + * Returns a mutable builder for constructing an instance of [ProjectListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProjectListPageAsync]. */ + class Builder internal constructor() { + + private var service: ProjectServiceAsync? = null + private var params: ProjectListParams? = null + private var response: ProjectListPageResponse? = null + + @JvmSynthetic + internal fun from(projectListPageAsync: ProjectListPageAsync) = apply { + service = projectListPageAsync.service + params = projectListPageAsync.params + response = projectListPageAsync.response + } + + fun service(service: ProjectServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: ProjectListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ProjectListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [ProjectListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProjectListPageAsync = + ProjectListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: ProjectListPageAsync) { @@ -104,4 +142,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ProjectListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "ProjectListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt index 038d6723..ad6b1c2d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.ProjectScoreService import java.util.Objects import java.util.Optional @@ -9,20 +10,14 @@ import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * List out all project_scores. The project_scores are sorted by creation date, with the most - * recently-created project_scores coming first - */ +/** @see [ProjectScoreService.list] */ class ProjectScoreListPage private constructor( - private val projectScoresService: ProjectScoreService, + private val service: ProjectScoreService, private val params: ProjectScoreListParams, private val response: ProjectScoreListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): ProjectScoreListPageResponse = response - /** * Delegates to [ProjectScoreListPageResponse], but gracefully handles missing data. * @@ -31,19 +26,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ProjectScoreListPage && projectScoresService == other.projectScoresService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(projectScoresService, params, response) /* spotless:on */ - - override fun toString() = - "ProjectScoreListPage{projectScoresService=$projectScoresService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -60,20 +42,75 @@ private constructor( ) } - fun getNextPage(): Optional { - return getNextPageParams().map { projectScoresService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): ProjectScoreListParams = params + + /** The response that this page was parsed from. */ + fun response(): ProjectScoreListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - projectScoresService: ProjectScoreService, - params: ProjectScoreListParams, - response: ProjectScoreListPageResponse, - ) = ProjectScoreListPage(projectScoresService, params, response) + /** + * Returns a mutable builder for constructing an instance of [ProjectScoreListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProjectScoreListPage]. */ + class Builder internal constructor() { + + private var service: ProjectScoreService? = null + private var params: ProjectScoreListParams? = null + private var response: ProjectScoreListPageResponse? = null + + @JvmSynthetic + internal fun from(projectScoreListPage: ProjectScoreListPage) = apply { + service = projectScoreListPage.service + params = projectScoreListPage.params + response = projectScoreListPage.response + } + + fun service(service: ProjectScoreService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: ProjectScoreListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ProjectScoreListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [ProjectScoreListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProjectScoreListPage = + ProjectScoreListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: ProjectScoreListPage) : Iterable { @@ -94,4 +131,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ProjectScoreListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "ProjectScoreListPage{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt index 98374dc7..66769492 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.ProjectScoreServiceAsync import java.util.Objects import java.util.Optional @@ -10,20 +11,14 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * List out all project_scores. The project_scores are sorted by creation date, with the most - * recently-created project_scores coming first - */ +/** @see [ProjectScoreServiceAsync.list] */ class ProjectScoreListPageAsync private constructor( - private val projectScoresService: ProjectScoreServiceAsync, + private val service: ProjectScoreServiceAsync, private val params: ProjectScoreListParams, private val response: ProjectScoreListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): ProjectScoreListPageResponse = response - /** * Delegates to [ProjectScoreListPageResponse], but gracefully handles missing data. * @@ -32,19 +27,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ProjectScoreListPageAsync && projectScoresService == other.projectScoresService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(projectScoresService, params, response) /* spotless:on */ - - override fun toString() = - "ProjectScoreListPageAsync{projectScoresService=$projectScoresService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -61,22 +43,78 @@ private constructor( ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { projectScoresService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): ProjectScoreListParams = params + + /** The response that this page was parsed from. */ + fun response(): ProjectScoreListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - projectScoresService: ProjectScoreServiceAsync, - params: ProjectScoreListParams, - response: ProjectScoreListPageResponse, - ) = ProjectScoreListPageAsync(projectScoresService, params, response) + /** + * Returns a mutable builder for constructing an instance of [ProjectScoreListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProjectScoreListPageAsync]. */ + class Builder internal constructor() { + + private var service: ProjectScoreServiceAsync? = null + private var params: ProjectScoreListParams? = null + private var response: ProjectScoreListPageResponse? = null + + @JvmSynthetic + internal fun from(projectScoreListPageAsync: ProjectScoreListPageAsync) = apply { + service = projectScoreListPageAsync.service + params = projectScoreListPageAsync.params + response = projectScoreListPageAsync.response + } + + fun service(service: ProjectScoreServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: ProjectScoreListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ProjectScoreListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [ProjectScoreListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProjectScoreListPageAsync = + ProjectScoreListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: ProjectScoreListPageAsync) { @@ -104,4 +142,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ProjectScoreListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "ProjectScoreListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt index 7482d0a8..6180b9a9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.ProjectTagService import java.util.Objects import java.util.Optional @@ -9,20 +10,14 @@ import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * List out all project_tags. The project_tags are sorted by creation date, with the most - * recently-created project_tags coming first - */ +/** @see [ProjectTagService.list] */ class ProjectTagListPage private constructor( - private val projectTagsService: ProjectTagService, + private val service: ProjectTagService, private val params: ProjectTagListParams, private val response: ProjectTagListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): ProjectTagListPageResponse = response - /** * Delegates to [ProjectTagListPageResponse], but gracefully handles missing data. * @@ -31,19 +26,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ProjectTagListPage && projectTagsService == other.projectTagsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(projectTagsService, params, response) /* spotless:on */ - - override fun toString() = - "ProjectTagListPage{projectTagsService=$projectTagsService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -60,20 +42,75 @@ private constructor( ) } - fun getNextPage(): Optional { - return getNextPageParams().map { projectTagsService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): ProjectTagListParams = params + + /** The response that this page was parsed from. */ + fun response(): ProjectTagListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - projectTagsService: ProjectTagService, - params: ProjectTagListParams, - response: ProjectTagListPageResponse, - ) = ProjectTagListPage(projectTagsService, params, response) + /** + * Returns a mutable builder for constructing an instance of [ProjectTagListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProjectTagListPage]. */ + class Builder internal constructor() { + + private var service: ProjectTagService? = null + private var params: ProjectTagListParams? = null + private var response: ProjectTagListPageResponse? = null + + @JvmSynthetic + internal fun from(projectTagListPage: ProjectTagListPage) = apply { + service = projectTagListPage.service + params = projectTagListPage.params + response = projectTagListPage.response + } + + fun service(service: ProjectTagService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: ProjectTagListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ProjectTagListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [ProjectTagListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProjectTagListPage = + ProjectTagListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: ProjectTagListPage) : Iterable { @@ -94,4 +131,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ProjectTagListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "ProjectTagListPage{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt index 533f9217..26fc37ac 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.ProjectTagServiceAsync import java.util.Objects import java.util.Optional @@ -10,20 +11,14 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * List out all project_tags. The project_tags are sorted by creation date, with the most - * recently-created project_tags coming first - */ +/** @see [ProjectTagServiceAsync.list] */ class ProjectTagListPageAsync private constructor( - private val projectTagsService: ProjectTagServiceAsync, + private val service: ProjectTagServiceAsync, private val params: ProjectTagListParams, private val response: ProjectTagListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): ProjectTagListPageResponse = response - /** * Delegates to [ProjectTagListPageResponse], but gracefully handles missing data. * @@ -32,19 +27,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ProjectTagListPageAsync && projectTagsService == other.projectTagsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(projectTagsService, params, response) /* spotless:on */ - - override fun toString() = - "ProjectTagListPageAsync{projectTagsService=$projectTagsService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -61,22 +43,78 @@ private constructor( ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { projectTagsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): ProjectTagListParams = params + + /** The response that this page was parsed from. */ + fun response(): ProjectTagListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - projectTagsService: ProjectTagServiceAsync, - params: ProjectTagListParams, - response: ProjectTagListPageResponse, - ) = ProjectTagListPageAsync(projectTagsService, params, response) + /** + * Returns a mutable builder for constructing an instance of [ProjectTagListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProjectTagListPageAsync]. */ + class Builder internal constructor() { + + private var service: ProjectTagServiceAsync? = null + private var params: ProjectTagListParams? = null + private var response: ProjectTagListPageResponse? = null + + @JvmSynthetic + internal fun from(projectTagListPageAsync: ProjectTagListPageAsync) = apply { + service = projectTagListPageAsync.service + params = projectTagListPageAsync.params + response = projectTagListPageAsync.response + } + + fun service(service: ProjectTagServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: ProjectTagListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ProjectTagListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [ProjectTagListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProjectTagListPageAsync = + ProjectTagListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: ProjectTagListPageAsync) { @@ -104,4 +142,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ProjectTagListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "ProjectTagListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt index 587a1c5d..abba5831 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.PromptService import java.util.Objects import java.util.Optional @@ -9,20 +10,14 @@ import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * List out all prompts. The prompts are sorted by creation date, with the most recently-created - * prompts coming first - */ +/** @see [PromptService.list] */ class PromptListPage private constructor( - private val promptsService: PromptService, + private val service: PromptService, private val params: PromptListParams, private val response: PromptListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): PromptListPageResponse = response - /** * Delegates to [PromptListPageResponse], but gracefully handles missing data. * @@ -31,19 +26,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is PromptListPage && promptsService == other.promptsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(promptsService, params, response) /* spotless:on */ - - override fun toString() = - "PromptListPage{promptsService=$promptsService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -60,20 +42,75 @@ private constructor( ) } - fun getNextPage(): Optional { - return getNextPageParams().map { promptsService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): PromptListParams = params + + /** The response that this page was parsed from. */ + fun response(): PromptListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - promptsService: PromptService, - params: PromptListParams, - response: PromptListPageResponse, - ) = PromptListPage(promptsService, params, response) + /** + * Returns a mutable builder for constructing an instance of [PromptListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PromptListPage]. */ + class Builder internal constructor() { + + private var service: PromptService? = null + private var params: PromptListParams? = null + private var response: PromptListPageResponse? = null + + @JvmSynthetic + internal fun from(promptListPage: PromptListPage) = apply { + service = promptListPage.service + params = promptListPage.params + response = promptListPage.response + } + + fun service(service: PromptService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: PromptListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: PromptListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [PromptListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PromptListPage = + PromptListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: PromptListPage) : Iterable { @@ -94,4 +131,16 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is PromptListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = "PromptListPage{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt index cfee8a95..e87031b9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.PromptServiceAsync import java.util.Objects import java.util.Optional @@ -10,20 +11,14 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * List out all prompts. The prompts are sorted by creation date, with the most recently-created - * prompts coming first - */ +/** @see [PromptServiceAsync.list] */ class PromptListPageAsync private constructor( - private val promptsService: PromptServiceAsync, + private val service: PromptServiceAsync, private val params: PromptListParams, private val response: PromptListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): PromptListPageResponse = response - /** * Delegates to [PromptListPageResponse], but gracefully handles missing data. * @@ -32,19 +27,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is PromptListPageAsync && promptsService == other.promptsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(promptsService, params, response) /* spotless:on */ - - override fun toString() = - "PromptListPageAsync{promptsService=$promptsService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -61,22 +43,78 @@ private constructor( ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { promptsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): PromptListParams = params + + /** The response that this page was parsed from. */ + fun response(): PromptListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - promptsService: PromptServiceAsync, - params: PromptListParams, - response: PromptListPageResponse, - ) = PromptListPageAsync(promptsService, params, response) + /** + * Returns a mutable builder for constructing an instance of [PromptListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PromptListPageAsync]. */ + class Builder internal constructor() { + + private var service: PromptServiceAsync? = null + private var params: PromptListParams? = null + private var response: PromptListPageResponse? = null + + @JvmSynthetic + internal fun from(promptListPageAsync: PromptListPageAsync) = apply { + service = promptListPageAsync.service + params = promptListPageAsync.params + response = promptListPageAsync.response + } + + fun service(service: PromptServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: PromptListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: PromptListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [PromptListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PromptListPageAsync = + PromptListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: PromptListPageAsync) { @@ -104,4 +142,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is PromptListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "PromptListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt index 7457585a..c9437627 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.RoleService import java.util.Objects import java.util.Optional @@ -9,20 +10,14 @@ import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * List out all roles. The roles are sorted by creation date, with the most recently-created roles - * coming first - */ +/** @see [RoleService.list] */ class RoleListPage private constructor( - private val rolesService: RoleService, + private val service: RoleService, private val params: RoleListParams, private val response: RoleListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): RoleListPageResponse = response - /** * Delegates to [RoleListPageResponse], but gracefully handles missing data. * @@ -31,19 +26,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is RoleListPage && rolesService == other.rolesService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(rolesService, params, response) /* spotless:on */ - - override fun toString() = - "RoleListPage{rolesService=$rolesService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -60,17 +42,75 @@ private constructor( ) } - fun getNextPage(): Optional { - return getNextPageParams().map { rolesService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): RoleListParams = params + + /** The response that this page was parsed from. */ + fun response(): RoleListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of(rolesService: RoleService, params: RoleListParams, response: RoleListPageResponse) = - RoleListPage(rolesService, params, response) + /** + * Returns a mutable builder for constructing an instance of [RoleListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoleListPage]. */ + class Builder internal constructor() { + + private var service: RoleService? = null + private var params: RoleListParams? = null + private var response: RoleListPageResponse? = null + + @JvmSynthetic + internal fun from(roleListPage: RoleListPage) = apply { + service = roleListPage.service + params = roleListPage.params + response = roleListPage.response + } + + fun service(service: RoleService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: RoleListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: RoleListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [RoleListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RoleListPage = + RoleListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: RoleListPage) : Iterable { @@ -91,4 +131,16 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is RoleListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = "RoleListPage{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt index 12e641a6..11469901 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.RoleServiceAsync import java.util.Objects import java.util.Optional @@ -10,20 +11,14 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * List out all roles. The roles are sorted by creation date, with the most recently-created roles - * coming first - */ +/** @see [RoleServiceAsync.list] */ class RoleListPageAsync private constructor( - private val rolesService: RoleServiceAsync, + private val service: RoleServiceAsync, private val params: RoleListParams, private val response: RoleListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): RoleListPageResponse = response - /** * Delegates to [RoleListPageResponse], but gracefully handles missing data. * @@ -32,19 +27,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is RoleListPageAsync && rolesService == other.rolesService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(rolesService, params, response) /* spotless:on */ - - override fun toString() = - "RoleListPageAsync{rolesService=$rolesService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -61,22 +43,78 @@ private constructor( ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { rolesService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): RoleListParams = params + + /** The response that this page was parsed from. */ + fun response(): RoleListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - rolesService: RoleServiceAsync, - params: RoleListParams, - response: RoleListPageResponse, - ) = RoleListPageAsync(rolesService, params, response) + /** + * Returns a mutable builder for constructing an instance of [RoleListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RoleListPageAsync]. */ + class Builder internal constructor() { + + private var service: RoleServiceAsync? = null + private var params: RoleListParams? = null + private var response: RoleListPageResponse? = null + + @JvmSynthetic + internal fun from(roleListPageAsync: RoleListPageAsync) = apply { + service = roleListPageAsync.service + params = roleListPageAsync.params + response = roleListPageAsync.response + } + + fun service(service: RoleServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: RoleListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: RoleListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [RoleListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RoleListPageAsync = + RoleListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: RoleListPageAsync) { @@ -104,4 +142,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is RoleListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "RoleListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt index cf61c6a6..40522df7 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.SpanIframeService import java.util.Objects import java.util.Optional @@ -9,20 +10,14 @@ import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * List out all span_iframes. The span_iframes are sorted by creation date, with the most - * recently-created span_iframes coming first - */ +/** @see [SpanIframeService.list] */ class SpanIframeListPage private constructor( - private val spanIframesService: SpanIframeService, + private val service: SpanIframeService, private val params: SpanIframeListParams, private val response: SpanIframeListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): SpanIframeListPageResponse = response - /** * Delegates to [SpanIframeListPageResponse], but gracefully handles missing data. * @@ -31,19 +26,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is SpanIframeListPage && spanIframesService == other.spanIframesService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(spanIframesService, params, response) /* spotless:on */ - - override fun toString() = - "SpanIframeListPage{spanIframesService=$spanIframesService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -60,20 +42,75 @@ private constructor( ) } - fun getNextPage(): Optional { - return getNextPageParams().map { spanIframesService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): SpanIframeListParams = params + + /** The response that this page was parsed from. */ + fun response(): SpanIframeListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - spanIframesService: SpanIframeService, - params: SpanIframeListParams, - response: SpanIframeListPageResponse, - ) = SpanIframeListPage(spanIframesService, params, response) + /** + * Returns a mutable builder for constructing an instance of [SpanIframeListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpanIframeListPage]. */ + class Builder internal constructor() { + + private var service: SpanIframeService? = null + private var params: SpanIframeListParams? = null + private var response: SpanIframeListPageResponse? = null + + @JvmSynthetic + internal fun from(spanIframeListPage: SpanIframeListPage) = apply { + service = spanIframeListPage.service + params = spanIframeListPage.params + response = spanIframeListPage.response + } + + fun service(service: SpanIframeService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: SpanIframeListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: SpanIframeListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [SpanIframeListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpanIframeListPage = + SpanIframeListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: SpanIframeListPage) : Iterable { @@ -94,4 +131,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is SpanIframeListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "SpanIframeListPage{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt index fd338a6a..7a564ec0 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.SpanIframeServiceAsync import java.util.Objects import java.util.Optional @@ -10,20 +11,14 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * List out all span_iframes. The span_iframes are sorted by creation date, with the most - * recently-created span_iframes coming first - */ +/** @see [SpanIframeServiceAsync.list] */ class SpanIframeListPageAsync private constructor( - private val spanIframesService: SpanIframeServiceAsync, + private val service: SpanIframeServiceAsync, private val params: SpanIframeListParams, private val response: SpanIframeListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): SpanIframeListPageResponse = response - /** * Delegates to [SpanIframeListPageResponse], but gracefully handles missing data. * @@ -32,19 +27,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is SpanIframeListPageAsync && spanIframesService == other.spanIframesService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(spanIframesService, params, response) /* spotless:on */ - - override fun toString() = - "SpanIframeListPageAsync{spanIframesService=$spanIframesService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -61,22 +43,78 @@ private constructor( ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { spanIframesService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): SpanIframeListParams = params + + /** The response that this page was parsed from. */ + fun response(): SpanIframeListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - spanIframesService: SpanIframeServiceAsync, - params: SpanIframeListParams, - response: SpanIframeListPageResponse, - ) = SpanIframeListPageAsync(spanIframesService, params, response) + /** + * Returns a mutable builder for constructing an instance of [SpanIframeListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SpanIframeListPageAsync]. */ + class Builder internal constructor() { + + private var service: SpanIframeServiceAsync? = null + private var params: SpanIframeListParams? = null + private var response: SpanIframeListPageResponse? = null + + @JvmSynthetic + internal fun from(spanIframeListPageAsync: SpanIframeListPageAsync) = apply { + service = spanIframeListPageAsync.service + params = spanIframeListPageAsync.params + response = spanIframeListPageAsync.response + } + + fun service(service: SpanIframeServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: SpanIframeListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: SpanIframeListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [SpanIframeListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SpanIframeListPageAsync = + SpanIframeListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: SpanIframeListPageAsync) { @@ -104,4 +142,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is SpanIframeListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "SpanIframeListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt index 22e76313..25aaa0e1 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.UserService import java.util.Objects import java.util.Optional @@ -9,20 +10,14 @@ import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * List out all users. The users are sorted by creation date, with the most recently-created users - * coming first - */ +/** @see [UserService.list] */ class UserListPage private constructor( - private val usersService: UserService, + private val service: UserService, private val params: UserListParams, private val response: UserListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): UserListPageResponse = response - /** * Delegates to [UserListPageResponse], but gracefully handles missing data. * @@ -31,19 +26,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is UserListPage && usersService == other.usersService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(usersService, params, response) /* spotless:on */ - - override fun toString() = - "UserListPage{usersService=$usersService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -60,17 +42,75 @@ private constructor( ) } - fun getNextPage(): Optional { - return getNextPageParams().map { usersService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): UserListParams = params + + /** The response that this page was parsed from. */ + fun response(): UserListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of(usersService: UserService, params: UserListParams, response: UserListPageResponse) = - UserListPage(usersService, params, response) + /** + * Returns a mutable builder for constructing an instance of [UserListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UserListPage]. */ + class Builder internal constructor() { + + private var service: UserService? = null + private var params: UserListParams? = null + private var response: UserListPageResponse? = null + + @JvmSynthetic + internal fun from(userListPage: UserListPage) = apply { + service = userListPage.service + params = userListPage.params + response = userListPage.response + } + + fun service(service: UserService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: UserListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: UserListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [UserListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UserListPage = + UserListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: UserListPage) : Iterable { @@ -91,4 +131,16 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is UserListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = "UserListPage{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt index 6b7601a3..412a21a0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.UserServiceAsync import java.util.Objects import java.util.Optional @@ -10,20 +11,14 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * List out all users. The users are sorted by creation date, with the most recently-created users - * coming first - */ +/** @see [UserServiceAsync.list] */ class UserListPageAsync private constructor( - private val usersService: UserServiceAsync, + private val service: UserServiceAsync, private val params: UserListParams, private val response: UserListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): UserListPageResponse = response - /** * Delegates to [UserListPageResponse], but gracefully handles missing data. * @@ -32,19 +27,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is UserListPageAsync && usersService == other.usersService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(usersService, params, response) /* spotless:on */ - - override fun toString() = - "UserListPageAsync{usersService=$usersService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -61,22 +43,78 @@ private constructor( ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { usersService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): UserListParams = params + + /** The response that this page was parsed from. */ + fun response(): UserListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - usersService: UserServiceAsync, - params: UserListParams, - response: UserListPageResponse, - ) = UserListPageAsync(usersService, params, response) + /** + * Returns a mutable builder for constructing an instance of [UserListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UserListPageAsync]. */ + class Builder internal constructor() { + + private var service: UserServiceAsync? = null + private var params: UserListParams? = null + private var response: UserListPageResponse? = null + + @JvmSynthetic + internal fun from(userListPageAsync: UserListPageAsync) = apply { + service = userListPageAsync.service + params = userListPageAsync.params + response = userListPageAsync.response + } + + fun service(service: UserServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: UserListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: UserListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [UserListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UserListPageAsync = + UserListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: UserListPageAsync) { @@ -104,4 +142,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is UserListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "UserListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt index 7a9fbf97..820ea8ba 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.ViewService import java.util.Objects import java.util.Optional @@ -9,20 +10,14 @@ import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * List out all views. The views are sorted by creation date, with the most recently-created views - * coming first - */ +/** @see [ViewService.list] */ class ViewListPage private constructor( - private val viewsService: ViewService, + private val service: ViewService, private val params: ViewListParams, private val response: ViewListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): ViewListPageResponse = response - /** * Delegates to [ViewListPageResponse], but gracefully handles missing data. * @@ -31,19 +26,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ViewListPage && viewsService == other.viewsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(viewsService, params, response) /* spotless:on */ - - override fun toString() = - "ViewListPage{viewsService=$viewsService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -60,17 +42,75 @@ private constructor( ) } - fun getNextPage(): Optional { - return getNextPageParams().map { viewsService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): ViewListParams = params + + /** The response that this page was parsed from. */ + fun response(): ViewListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of(viewsService: ViewService, params: ViewListParams, response: ViewListPageResponse) = - ViewListPage(viewsService, params, response) + /** + * Returns a mutable builder for constructing an instance of [ViewListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ViewListPage]. */ + class Builder internal constructor() { + + private var service: ViewService? = null + private var params: ViewListParams? = null + private var response: ViewListPageResponse? = null + + @JvmSynthetic + internal fun from(viewListPage: ViewListPage) = apply { + service = viewListPage.service + params = viewListPage.params + response = viewListPage.response + } + + fun service(service: ViewService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: ViewListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ViewListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [ViewListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ViewListPage = + ViewListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: ViewListPage) : Iterable { @@ -91,4 +131,16 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ViewListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = "ViewListPage{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt index 20bae5b9..c5c6bd0e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.ViewServiceAsync import java.util.Objects import java.util.Optional @@ -10,20 +11,14 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * List out all views. The views are sorted by creation date, with the most recently-created views - * coming first - */ +/** @see [ViewServiceAsync.list] */ class ViewListPageAsync private constructor( - private val viewsService: ViewServiceAsync, + private val service: ViewServiceAsync, private val params: ViewListParams, private val response: ViewListPageResponse, ) { - /** Returns the response that this page was parsed from. */ - fun response(): ViewListPageResponse = response - /** * Delegates to [ViewListPageResponse], but gracefully handles missing data. * @@ -32,19 +27,6 @@ private constructor( fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ViewListPageAsync && viewsService == other.viewsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(viewsService, params, response) /* spotless:on */ - - override fun toString() = - "ViewListPageAsync{viewsService=$viewsService, params=$params, response=$response}" - fun hasNextPage(): Boolean = objects().isNotEmpty() fun getNextPageParams(): Optional { @@ -61,22 +43,78 @@ private constructor( ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { viewsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) + /** The parameters that were used to request this page. */ + fun params(): ViewListParams = params + + /** The response that this page was parsed from. */ + fun response(): ViewListPageResponse = response + + fun toBuilder() = Builder().from(this) + companion object { - @JvmStatic - fun of( - viewsService: ViewServiceAsync, - params: ViewListParams, - response: ViewListPageResponse, - ) = ViewListPageAsync(viewsService, params, response) + /** + * Returns a mutable builder for constructing an instance of [ViewListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ViewListPageAsync]. */ + class Builder internal constructor() { + + private var service: ViewServiceAsync? = null + private var params: ViewListParams? = null + private var response: ViewListPageResponse? = null + + @JvmSynthetic + internal fun from(viewListPageAsync: ViewListPageAsync) = apply { + service = viewListPageAsync.service + params = viewListPageAsync.params + response = viewListPageAsync.response + } + + fun service(service: ViewServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: ViewListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ViewListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [ViewListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ViewListPageAsync = + ViewListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: ViewListPageAsync) { @@ -104,4 +142,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ViewListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "ViewListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AclServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AclServiceAsyncImpl.kt index bea90cc4..2cde27c7 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AclServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AclServiceAsyncImpl.kt @@ -169,7 +169,11 @@ class AclServiceAsyncImpl internal constructor(private val clientOptions: Client } } .let { - AclListPageAsync.of(AclServiceAsyncImpl(clientOptions), params, it) + AclListPageAsync.builder() + .service(AclServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsyncImpl.kt index 2c8c8b6b..5cd2d51e 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsyncImpl.kt @@ -206,11 +206,11 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C } } .let { - AiSecretListPageAsync.of( - AiSecretServiceAsyncImpl(clientOptions), - params, - it, - ) + AiSecretListPageAsync.builder() + .service(AiSecretServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsyncImpl.kt index a552fb23..c0298579 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsyncImpl.kt @@ -153,11 +153,11 @@ class ApiKeyServiceAsyncImpl internal constructor(private val clientOptions: Cli } } .let { - ApiKeyListPageAsync.of( - ApiKeyServiceAsyncImpl(clientOptions), - params, - it, - ) + ApiKeyListPageAsync.builder() + .service(ApiKeyServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsyncImpl.kt index 003396d2..14e26354 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsyncImpl.kt @@ -234,11 +234,11 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl } } .let { - DatasetListPageAsync.of( - DatasetServiceAsyncImpl(clientOptions), - params, - it, - ) + DatasetListPageAsync.builder() + .service(DatasetServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsyncImpl.kt index 8068d0df..1b41174a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsyncImpl.kt @@ -234,11 +234,11 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: } } .let { - ExperimentListPageAsync.of( - ExperimentServiceAsyncImpl(clientOptions), - params, - it, - ) + ExperimentListPageAsync.builder() + .service(ExperimentServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsyncImpl.kt index 30e5ddb3..b646d9eb 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsyncImpl.kt @@ -208,11 +208,11 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C } } .let { - FunctionListPageAsync.of( - FunctionServiceAsyncImpl(clientOptions), - params, - it, - ) + FunctionListPageAsync.builder() + .service(FunctionServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/GroupServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/GroupServiceAsyncImpl.kt index e22c95a3..e434a12f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/GroupServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/GroupServiceAsyncImpl.kt @@ -198,11 +198,11 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie } } .let { - GroupListPageAsync.of( - GroupServiceAsyncImpl(clientOptions), - params, - it, - ) + GroupListPageAsync.builder() + .service(GroupServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsyncImpl.kt index 317c1bbc..00950daa 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsyncImpl.kt @@ -164,11 +164,11 @@ class OrganizationServiceAsyncImpl internal constructor(private val clientOption } } .let { - OrganizationListPageAsync.of( - OrganizationServiceAsyncImpl(clientOptions), - params, - it, - ) + OrganizationListPageAsync.builder() + .service(OrganizationServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsyncImpl.kt index c27a72ce..3d22e48b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsyncImpl.kt @@ -198,11 +198,11 @@ class ProjectScoreServiceAsyncImpl internal constructor(private val clientOption } } .let { - ProjectScoreListPageAsync.of( - ProjectScoreServiceAsyncImpl(clientOptions), - params, - it, - ) + ProjectScoreListPageAsync.builder() + .service(ProjectScoreServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsyncImpl.kt index 4945d7a9..0953c5f2 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsyncImpl.kt @@ -202,11 +202,11 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl } } .let { - ProjectListPageAsync.of( - ProjectServiceAsyncImpl(clientOptions), - params, - it, - ) + ProjectListPageAsync.builder() + .service(ProjectServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsyncImpl.kt index f83e7507..193e671e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsyncImpl.kt @@ -198,11 +198,11 @@ class ProjectTagServiceAsyncImpl internal constructor(private val clientOptions: } } .let { - ProjectTagListPageAsync.of( - ProjectTagServiceAsyncImpl(clientOptions), - params, - it, - ) + ProjectTagListPageAsync.builder() + .service(ProjectTagServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/PromptServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/PromptServiceAsyncImpl.kt index eb1c6ce3..32bdece7 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/PromptServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/PromptServiceAsyncImpl.kt @@ -198,11 +198,11 @@ class PromptServiceAsyncImpl internal constructor(private val clientOptions: Cli } } .let { - PromptListPageAsync.of( - PromptServiceAsyncImpl(clientOptions), - params, - it, - ) + PromptListPageAsync.builder() + .service(PromptServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/RoleServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/RoleServiceAsyncImpl.kt index 3081cfb0..0da885cc 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/RoleServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/RoleServiceAsyncImpl.kt @@ -198,11 +198,11 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien } } .let { - RoleListPageAsync.of( - RoleServiceAsyncImpl(clientOptions), - params, - it, - ) + RoleListPageAsync.builder() + .service(RoleServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsyncImpl.kt index 7ce568c6..843f6b1e 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsyncImpl.kt @@ -198,11 +198,11 @@ class SpanIframeServiceAsyncImpl internal constructor(private val clientOptions: } } .let { - SpanIframeListPageAsync.of( - SpanIframeServiceAsyncImpl(clientOptions), - params, - it, - ) + SpanIframeListPageAsync.builder() + .service(SpanIframeServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/UserServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/UserServiceAsyncImpl.kt index 57d9116b..b5d79eb8 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/UserServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/UserServiceAsyncImpl.kt @@ -105,11 +105,11 @@ class UserServiceAsyncImpl internal constructor(private val clientOptions: Clien } } .let { - UserListPageAsync.of( - UserServiceAsyncImpl(clientOptions), - params, - it, - ) + UserListPageAsync.builder() + .service(UserServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ViewServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ViewServiceAsyncImpl.kt index 423ac8e6..35a95111 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ViewServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ViewServiceAsyncImpl.kt @@ -198,11 +198,11 @@ class ViewServiceAsyncImpl internal constructor(private val clientOptions: Clien } } .let { - ViewListPageAsync.of( - ViewServiceAsyncImpl(clientOptions), - params, - it, - ) + ViewListPageAsync.builder() + .service(ViewServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AclServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AclServiceImpl.kt index ebb50632..6511ad61 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AclServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AclServiceImpl.kt @@ -146,7 +146,13 @@ class AclServiceImpl internal constructor(private val clientOptions: ClientOptio it.validate() } } - .let { AclListPage.of(AclServiceImpl(clientOptions), params, it) } + .let { + AclListPage.builder() + .service(AclServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AiSecretServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AiSecretServiceImpl.kt index da10ac38..e5da7242 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AiSecretServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AiSecretServiceImpl.kt @@ -181,7 +181,13 @@ class AiSecretServiceImpl internal constructor(private val clientOptions: Client it.validate() } } - .let { AiSecretListPage.of(AiSecretServiceImpl(clientOptions), params, it) } + .let { + AiSecretListPage.builder() + .service(AiSecretServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ApiKeyServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ApiKeyServiceImpl.kt index d3adf2df..dd948b0d 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ApiKeyServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ApiKeyServiceImpl.kt @@ -134,7 +134,13 @@ class ApiKeyServiceImpl internal constructor(private val clientOptions: ClientOp it.validate() } } - .let { ApiKeyListPage.of(ApiKeyServiceImpl(clientOptions), params, it) } + .let { + ApiKeyListPage.builder() + .service(ApiKeyServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/DatasetServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/DatasetServiceImpl.kt index 2f8d8cbb..39a0a0e3 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/DatasetServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/DatasetServiceImpl.kt @@ -206,7 +206,13 @@ class DatasetServiceImpl internal constructor(private val clientOptions: ClientO it.validate() } } - .let { DatasetListPage.of(DatasetServiceImpl(clientOptions), params, it) } + .let { + DatasetListPage.builder() + .service(DatasetServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ExperimentServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ExperimentServiceImpl.kt index d7692a2a..f7d1da12 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ExperimentServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ExperimentServiceImpl.kt @@ -221,7 +221,13 @@ class ExperimentServiceImpl internal constructor(private val clientOptions: Clie it.validate() } } - .let { ExperimentListPage.of(ExperimentServiceImpl(clientOptions), params, it) } + .let { + ExperimentListPage.builder() + .service(ExperimentServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceImpl.kt index e0659a16..9658b5bc 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceImpl.kt @@ -183,7 +183,13 @@ class FunctionServiceImpl internal constructor(private val clientOptions: Client it.validate() } } - .let { FunctionListPage.of(FunctionServiceImpl(clientOptions), params, it) } + .let { + FunctionListPage.builder() + .service(FunctionServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/GroupServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/GroupServiceImpl.kt index 09e6a822..30e51563 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/GroupServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/GroupServiceImpl.kt @@ -167,7 +167,13 @@ class GroupServiceImpl internal constructor(private val clientOptions: ClientOpt it.validate() } } - .let { GroupListPage.of(GroupServiceImpl(clientOptions), params, it) } + .let { + GroupListPage.builder() + .service(GroupServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/OrganizationServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/OrganizationServiceImpl.kt index b7601af9..ea53c72a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/OrganizationServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/OrganizationServiceImpl.kt @@ -155,7 +155,11 @@ class OrganizationServiceImpl internal constructor(private val clientOptions: Cl } } .let { - OrganizationListPage.of(OrganizationServiceImpl(clientOptions), params, it) + OrganizationListPage.builder() + .service(OrganizationServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreServiceImpl.kt index adc774d6..78c4f8ce 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreServiceImpl.kt @@ -186,7 +186,11 @@ class ProjectScoreServiceImpl internal constructor(private val clientOptions: Cl } } .let { - ProjectScoreListPage.of(ProjectScoreServiceImpl(clientOptions), params, it) + ProjectScoreListPage.builder() + .service(ProjectScoreServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectServiceImpl.kt index 5ce00751..7ccbce80 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectServiceImpl.kt @@ -174,7 +174,13 @@ class ProjectServiceImpl internal constructor(private val clientOptions: ClientO it.validate() } } - .let { ProjectListPage.of(ProjectServiceImpl(clientOptions), params, it) } + .let { + ProjectListPage.builder() + .service(ProjectServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectTagServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectTagServiceImpl.kt index d71558f6..17629219 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectTagServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectTagServiceImpl.kt @@ -185,7 +185,13 @@ class ProjectTagServiceImpl internal constructor(private val clientOptions: Clie it.validate() } } - .let { ProjectTagListPage.of(ProjectTagServiceImpl(clientOptions), params, it) } + .let { + ProjectTagListPage.builder() + .service(ProjectTagServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/PromptServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/PromptServiceImpl.kt index 12ceab83..105c1629 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/PromptServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/PromptServiceImpl.kt @@ -167,7 +167,13 @@ class PromptServiceImpl internal constructor(private val clientOptions: ClientOp it.validate() } } - .let { PromptListPage.of(PromptServiceImpl(clientOptions), params, it) } + .let { + PromptListPage.builder() + .service(PromptServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/RoleServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/RoleServiceImpl.kt index 97099679..12949e33 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/RoleServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/RoleServiceImpl.kt @@ -166,7 +166,13 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti it.validate() } } - .let { RoleListPage.of(RoleServiceImpl(clientOptions), params, it) } + .let { + RoleListPage.builder() + .service(RoleServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/SpanIframeServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/SpanIframeServiceImpl.kt index b522cf8b..d094ddea 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/SpanIframeServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/SpanIframeServiceImpl.kt @@ -185,7 +185,13 @@ class SpanIframeServiceImpl internal constructor(private val clientOptions: Clie it.validate() } } - .let { SpanIframeListPage.of(SpanIframeServiceImpl(clientOptions), params, it) } + .let { + SpanIframeListPage.builder() + .service(SpanIframeServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/UserServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/UserServiceImpl.kt index 8629234a..ade1f669 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/UserServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/UserServiceImpl.kt @@ -91,7 +91,13 @@ class UserServiceImpl internal constructor(private val clientOptions: ClientOpti it.validate() } } - .let { UserListPage.of(UserServiceImpl(clientOptions), params, it) } + .let { + UserListPage.builder() + .service(UserServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ViewServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ViewServiceImpl.kt index c7af6b57..823fa36e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ViewServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ViewServiceImpl.kt @@ -166,7 +166,13 @@ class ViewServiceImpl internal constructor(private val clientOptions: ClientOpti it.validate() } } - .let { ViewListPage.of(ViewServiceImpl(clientOptions), params, it) } + .let { + ViewListPage.builder() + .service(ViewServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } From 491a2aeecc8b972efec17ec3e62e2848d1020158 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 10 Apr 2025 04:41:51 +0000 Subject: [PATCH 35/42] chore(internal): reduce CI branch coverage --- .github/workflows/ci.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a6ae118..ebbaa260 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,19 +1,17 @@ name: CI on: push: - branches-ignore: - - 'generated' - - 'codegen/**' - - 'integrated/**' - - 'preview-head/**' - - 'preview-base/**' - - 'preview/**' + branches: + - main + pull_request: + branches: + - main + - next jobs: lint: name: lint runs-on: ubuntu-latest - steps: - uses: actions/checkout@v4 From 732dd768a9e4f048edf415d697e89c36551414d8 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 15 Apr 2025 04:21:01 +0000 Subject: [PATCH 36/42] chore(internal): codegen related update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a08df254..aa3af1a3 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ It is generated with [Stainless](https://www.stainless.com/). -The REST API documentation can be found on [www.braintrustdata.com](https://www.braintrustdata.com/docs/api/spec). Javadocs are also available on [javadoc.io](https://javadoc.io/doc/com.braintrustdata.api/braintrust-java/0.8.0). +The REST API documentation can be found on [www.braintrustdata.com](https://www.braintrustdata.com/docs/api/spec). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.braintrustdata.api/braintrust-java/0.8.0). From 6039ca545cba51e71e02f4db3b26a0964f3bd522 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 16 Apr 2025 03:31:17 +0000 Subject: [PATCH 37/42] docs(client): update jackson compat error message --- .../src/main/kotlin/com/braintrustdata/api/core/Check.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Check.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Check.kt index dc20c15d..66e86d49 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Check.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Check.kt @@ -62,7 +62,7 @@ internal fun checkJacksonVersionCompatibility() { } check(incompatibleJacksonVersions.isEmpty()) { """ -This SDK depends on Jackson version $MINIMUM_JACKSON_VERSION, but the following incompatible Jackson versions were detected at runtime: +This SDK requires a minimum Jackson version of $MINIMUM_JACKSON_VERSION, but the following incompatible Jackson versions were detected at runtime: ${incompatibleJacksonVersions.asSequence().map { (version, incompatibilityReason) -> "- `${version.toFullString().replace("/", ":")}` ($incompatibilityReason)" From 8fd288d5ef4d5053f20b7db81bde980a465d996b Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 16 Apr 2025 03:52:53 +0000 Subject: [PATCH 38/42] docs: explain jackson compat in readme --- README.md | 11 +++++++++++ .../main/kotlin/com/braintrustdata/api/core/Check.kt | 2 ++ 2 files changed, 13 insertions(+) diff --git a/README.md b/README.md index aa3af1a3..93e3b92a 100644 --- a/README.md +++ b/README.md @@ -283,6 +283,17 @@ Or to `debug` for more verbose logging: $ export BRAINTRUST_LOG=debug ``` +## Jackson + +The SDK depends on [Jackson](https://github.com/FasterXML/jackson) for JSON serialization/deserialization. It is compatible with version 2.13.4 or higher, but depends on version 2.18.2 by default. + +The SDK throws an exception if it detects an incompatible Jackson version at runtime (e.g. if the default version was overridden in your Maven or Gradle config). + +If the SDK threw an exception, but you're _certain_ the version is compatible, then disable the version check using the `checkJacksonVersionCompatibility` on [`BraintrustOkHttpClient`](braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClient.kt) or [`BraintrustOkHttpClientAsync`](braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClientAsync.kt). + +> [!CAUTION] +> We make no guarantee that the SDK works correctly when the Jackson version check is disabled. + ## Network options ### Retries diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Check.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Check.kt index 66e86d49..7b05d4da 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Check.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Check.kt @@ -73,6 +73,8 @@ This can happen if you are either: 2. Depending on some library that depends on different Jackson versions, potentially transitively Double-check that you are depending on compatible Jackson versions. + +See https://www.github.com/braintrustdata/braintrust-java#jackson for more information. """ .trimIndent() } From 8efd75a6d5b017099440e5dbb0b97d2b77d56c13 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 17 Apr 2025 03:30:54 +0000 Subject: [PATCH 39/42] perf(internal): improve compilation+test speed --- .github/workflows/publish-sonatype.yml | 2 +- .../api/core/http/RetryingHttpClient.kt | 56 ++++++++++++------- .../api/core/PhantomReachableTest.kt | 2 +- .../api/core/http/HeadersTest.kt | 32 ----------- .../api/core/http/QueryParamsTest.kt | 32 ----------- .../api/core/http/RetryingHttpClientTest.kt | 36 ++++++++---- .../api/services/ErrorHandlingTest.kt | 2 + .../api/services/ServiceParamsTest.kt | 2 + .../main/kotlin/braintrust.kotlin.gradle.kts | 9 +-- gradle.properties | 16 +++++- 10 files changed, 85 insertions(+), 104 deletions(-) diff --git a/.github/workflows/publish-sonatype.yml b/.github/workflows/publish-sonatype.yml index a1f76188..bab4aea6 100755 --- a/.github/workflows/publish-sonatype.yml +++ b/.github/workflows/publish-sonatype.yml @@ -33,7 +33,7 @@ jobs: export -- GPG_SIGNING_KEY_ID printenv -- GPG_SIGNING_KEY | gpg --batch --passphrase-fd 3 --import 3<<< "$GPG_SIGNING_PASSWORD" GPG_SIGNING_KEY_ID="$(gpg --with-colons --list-keys | awk -F : -- '/^pub:/ { getline; print "0x" substr($10, length($10) - 7) }')" - ./gradlew publishAndReleaseToMavenCentral --stacktrace -PmavenCentralUsername="$SONATYPE_USERNAME" -PmavenCentralPassword="$SONATYPE_PASSWORD" + ./gradlew publishAndReleaseToMavenCentral --stacktrace -PmavenCentralUsername="$SONATYPE_USERNAME" -PmavenCentralPassword="$SONATYPE_PASSWORD" --no-configuration-cache env: SONATYPE_USERNAME: ${{ secrets.BRAINTRUST_SONATYPE_USERNAME || secrets.SONATYPE_USERNAME }} SONATYPE_PASSWORD: ${{ secrets.BRAINTRUST_SONATYPE_PASSWORD || secrets.SONATYPE_PASSWORD }} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/RetryingHttpClient.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/RetryingHttpClient.kt index 56bdac87..830c55cc 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/RetryingHttpClient.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/RetryingHttpClient.kt @@ -23,6 +23,7 @@ import kotlin.math.pow class RetryingHttpClient private constructor( private val httpClient: HttpClient, + private val sleeper: Sleeper, private val clock: Clock, private val maxRetries: Int, private val idempotencyHeader: String?, @@ -62,10 +63,10 @@ private constructor( null } - val backoffMillis = getRetryBackoffMillis(retries, response) + val backoffDuration = getRetryBackoffDuration(retries, response) // All responses must be closed, so close the failed one before retrying. response?.close() - Thread.sleep(backoffMillis.toMillis()) + sleeper.sleep(backoffDuration) } } @@ -111,10 +112,10 @@ private constructor( } } - val backoffMillis = getRetryBackoffMillis(retries, response) + val backoffDuration = getRetryBackoffDuration(retries, response) // All responses must be closed, so close the failed one before retrying. response?.close() - return sleepAsync(backoffMillis.toMillis()).thenCompose { + return sleeper.sleepAsync(backoffDuration).thenCompose { executeWithRetries(requestWithRetryCount, requestOptions) } } @@ -179,7 +180,7 @@ private constructor( // retried. throwable is IOException || throwable is BraintrustIoException - private fun getRetryBackoffMillis(retries: Int, response: HttpResponse?): Duration { + private fun getRetryBackoffDuration(retries: Int, response: HttpResponse?): Duration { // About the Retry-After header: // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After response @@ -226,33 +227,40 @@ private constructor( companion object { - private val TIMER = Timer("RetryingHttpClient", true) - - private fun sleepAsync(millis: Long): CompletableFuture { - val future = CompletableFuture() - TIMER.schedule( - object : TimerTask() { - override fun run() { - future.complete(null) - } - }, - millis, - ) - return future - } - @JvmStatic fun builder() = Builder() } class Builder internal constructor() { private var httpClient: HttpClient? = null + private var sleeper: Sleeper = + object : Sleeper { + + private val timer = Timer("RetryingHttpClient", true) + + override fun sleep(duration: Duration) = Thread.sleep(duration.toMillis()) + + override fun sleepAsync(duration: Duration): CompletableFuture { + val future = CompletableFuture() + timer.schedule( + object : TimerTask() { + override fun run() { + future.complete(null) + } + }, + duration.toMillis(), + ) + return future + } + } private var clock: Clock = Clock.systemUTC() private var maxRetries: Int = 2 private var idempotencyHeader: String? = null fun httpClient(httpClient: HttpClient) = apply { this.httpClient = httpClient } + @JvmSynthetic internal fun sleeper(sleeper: Sleeper) = apply { this.sleeper = sleeper } + fun clock(clock: Clock) = apply { this.clock = clock } fun maxRetries(maxRetries: Int) = apply { this.maxRetries = maxRetries } @@ -262,9 +270,17 @@ private constructor( fun build(): HttpClient = RetryingHttpClient( checkRequired("httpClient", httpClient), + sleeper, clock, maxRetries, idempotencyHeader, ) } + + internal interface Sleeper { + + fun sleep(duration: Duration) + + fun sleepAsync(duration: Duration): CompletableFuture + } } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/PhantomReachableTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/PhantomReachableTest.kt index a7a9b514..787e3b1f 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/PhantomReachableTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/PhantomReachableTest.kt @@ -20,7 +20,7 @@ internal class PhantomReachableTest { assertThat(closed).isFalse() System.gc() - Thread.sleep(3000) + Thread.sleep(100) assertThat(closed).isTrue() } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/HeadersTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/HeadersTest.kt index 2a5ed57a..a4e77e29 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/HeadersTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/HeadersTest.kt @@ -1,8 +1,6 @@ package com.braintrustdata.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 @@ -241,34 +239,4 @@ internal class HeadersTest { 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/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/QueryParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/QueryParamsTest.kt index 08e55c66..0fd285c1 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/QueryParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/QueryParamsTest.kt @@ -1,8 +1,6 @@ package com.braintrustdata.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 @@ -179,34 +177,4 @@ internal class QueryParamsTest { 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/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/RetryingHttpClientTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/RetryingHttpClientTest.kt index d538b9b3..cb68648b 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/RetryingHttpClientTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/RetryingHttpClientTest.kt @@ -7,13 +7,16 @@ import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo import com.github.tomakehurst.wiremock.junit5.WireMockTest import com.github.tomakehurst.wiremock.stubbing.Scenario import java.io.InputStream +import java.time.Duration import java.util.concurrent.CompletableFuture import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.parallel.ResourceLock import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ValueSource @WireMockTest +@ResourceLock("https://github.com/wiremock/wiremock/issues/169") internal class RetryingHttpClientTest { private var openResponseCount = 0 @@ -24,6 +27,7 @@ internal class RetryingHttpClientTest { val okHttpClient = OkHttpClient.builder().baseUrl(wmRuntimeInfo.httpBaseUrl).build() httpClient = object : HttpClient { + override fun execute( request: HttpRequest, requestOptions: RequestOptions, @@ -40,6 +44,7 @@ internal class RetryingHttpClientTest { private fun trackClose(response: HttpResponse): HttpResponse { openResponseCount++ return object : HttpResponse { + private var isClosed = false override fun statusCode(): Int = response.statusCode() @@ -66,7 +71,7 @@ internal class RetryingHttpClientTest { @ValueSource(booleans = [false, true]) fun execute(async: Boolean) { stubFor(post(urlPathEqualTo("/something")).willReturn(ok())) - val retryingClient = RetryingHttpClient.builder().httpClient(httpClient).build() + val retryingClient = retryingHttpClientBuilder().build() val response = retryingClient.execute( @@ -88,11 +93,7 @@ internal class RetryingHttpClientTest { .willReturn(ok()) ) val retryingClient = - RetryingHttpClient.builder() - .httpClient(httpClient) - .maxRetries(2) - .idempotencyHeader("X-Some-Header") - .build() + retryingHttpClientBuilder().maxRetries(2).idempotencyHeader("X-Some-Header").build() val response = retryingClient.execute( @@ -134,8 +135,7 @@ internal class RetryingHttpClientTest { .willReturn(ok()) .willSetStateTo("COMPLETED") ) - val retryingClient = - RetryingHttpClient.builder().httpClient(httpClient).maxRetries(2).build() + val retryingClient = retryingHttpClientBuilder().maxRetries(2).build() val response = retryingClient.execute( @@ -181,8 +181,7 @@ internal class RetryingHttpClientTest { .willReturn(ok()) .willSetStateTo("COMPLETED") ) - val retryingClient = - RetryingHttpClient.builder().httpClient(httpClient).maxRetries(2).build() + val retryingClient = retryingHttpClientBuilder().maxRetries(2).build() val response = retryingClient.execute( @@ -220,8 +219,7 @@ internal class RetryingHttpClientTest { .willReturn(ok()) .willSetStateTo("COMPLETED") ) - val retryingClient = - RetryingHttpClient.builder().httpClient(httpClient).maxRetries(1).build() + val retryingClient = retryingHttpClientBuilder().maxRetries(1).build() val response = retryingClient.execute( @@ -234,6 +232,20 @@ internal class RetryingHttpClientTest { assertNoResponseLeaks() } + private fun retryingHttpClientBuilder() = + RetryingHttpClient.builder() + .httpClient(httpClient) + // Use a no-op `Sleeper` to make the test fast. + .sleeper( + object : RetryingHttpClient.Sleeper { + + override fun sleep(duration: Duration) {} + + override fun sleepAsync(duration: Duration): CompletableFuture = + CompletableFuture.completedFuture(null) + } + ) + private fun HttpClient.execute(request: HttpRequest, async: Boolean): HttpResponse = if (async) executeAsync(request).get() else execute(request) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/ErrorHandlingTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/ErrorHandlingTest.kt index 56b5baef..d1b745a7 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/ErrorHandlingTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/ErrorHandlingTest.kt @@ -28,8 +28,10 @@ import org.assertj.core.api.Assertions.entry import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.api.parallel.ResourceLock @WireMockTest +@ResourceLock("https://github.com/wiremock/wiremock/issues/169") internal class ErrorHandlingTest { companion object { diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/ServiceParamsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/ServiceParamsTest.kt index 9e25370e..436926c8 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/ServiceParamsTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/ServiceParamsTest.kt @@ -18,8 +18,10 @@ import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo import com.github.tomakehurst.wiremock.junit5.WireMockTest import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test +import org.junit.jupiter.api.parallel.ResourceLock @WireMockTest +@ResourceLock("https://github.com/wiremock/wiremock/issues/169") internal class ServiceParamsTest { private lateinit var client: BraintrustClient diff --git a/buildSrc/src/main/kotlin/braintrust.kotlin.gradle.kts b/buildSrc/src/main/kotlin/braintrust.kotlin.gradle.kts index 51f8461b..14b60c20 100755 --- a/buildSrc/src/main/kotlin/braintrust.kotlin.gradle.kts +++ b/buildSrc/src/main/kotlin/braintrust.kotlin.gradle.kts @@ -9,7 +9,7 @@ plugins { kotlin { jvmToolchain { - languageVersion.set(JavaLanguageVersion.of(17)) + languageVersion.set(JavaLanguageVersion.of(21)) } compilerOptions { @@ -19,6 +19,8 @@ kotlin { // Suppress deprecation warnings because we may still reference and test deprecated members. // TODO: Replace with `-Xsuppress-warning=DEPRECATION` once we use Kotlin compiler 2.1.0+. "-nowarn", + // Use as many threads as there are CPU cores on the machine for compilation. + "-Xbackend-threads=0", ) jvmTarget.set(JvmTarget.JVM_1_8) languageVersion.set(KotlinVersion.KOTLIN_1_8) @@ -34,8 +36,7 @@ configure { } } -// Run tests in parallel to some degree. tasks.withType().configureEach { - maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).coerceAtLeast(1) - forkEvery = 100 + systemProperty("junit.jupiter.execution.parallel.enabled", true) + systemProperty("junit.jupiter.execution.parallel.mode.default", "concurrent") } diff --git a/gradle.properties b/gradle.properties index 0c8d4ded..ff76593f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,17 @@ org.gradle.caching=true +org.gradle.configuration-cache=true org.gradle.parallel=true org.gradle.daemon=false -org.gradle.jvmargs=-Xmx4g -kotlin.daemon.jvmargs=-Xmx4g +# These options improve our compilation and test performance. They are inherited by the Kotlin daemon. +org.gradle.jvmargs=\ + -Xms1g \ + -Xmx4g \ + -XX:+UseParallelGC \ + -XX:InitialCodeCacheSize=256m \ + -XX:ReservedCodeCacheSize=1G \ + -XX:MetaspaceSize=256m \ + -XX:TieredStopAtLevel=1 \ + -XX:GCTimeRatio=4 \ + -XX:CICompilerCount=4 \ + -XX:+OptimizeStringConcat \ + -XX:+UseStringDeduplication From 1388be42ac426c5d1b934712302c6acecf20c885 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 17 Apr 2025 03:44:05 +0000 Subject: [PATCH 40/42] docs: explain http client customization --- README.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/README.md b/README.md index 93e3b92a..4eac9576 100644 --- a/README.md +++ b/README.md @@ -370,6 +370,42 @@ BraintrustClient client = BraintrustOkHttpClient.builder() .build(); ``` +### Custom HTTP client + +The SDK consists of three artifacts: + +- `braintrust-java-core` + - Contains core SDK logic + - Does not depend on [OkHttp](https://square.github.io/okhttp) + - Exposes [`BraintrustClient`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClient.kt), [`BraintrustClientAsync`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientAsync.kt), [`BraintrustClientImpl`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientImpl.kt), and [`BraintrustClientAsyncImpl`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientAsyncImpl.kt), all of which can work with any HTTP client +- `braintrust-java-client-okhttp` + - Depends on [OkHttp](https://square.github.io/okhttp) + - Exposes [`BraintrustOkHttpClient`](braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClient.kt) and [`BraintrustOkHttpClientAsync`](braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClientAsync.kt), which provide a way to construct [`BraintrustClientImpl`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientImpl.kt) and [`BraintrustClientAsyncImpl`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientAsyncImpl.kt), respectively, using OkHttp +- `braintrust-java` + - Depends on and exposes the APIs of both `braintrust-java-core` and `braintrust-java-client-okhttp` + - Does not have its own logic + +This structure allows replacing the SDK's default HTTP client without pulling in unnecessary dependencies. + +#### Customized [`OkHttpClient`](https://square.github.io/okhttp/3.x/okhttp/okhttp3/OkHttpClient.html) + +> [!TIP] +> Try the available [network options](#network-options) before replacing the default client. + +To use a customized `OkHttpClient`: + +1. Replace your [`braintrust-java` dependency](#installation) with `braintrust-java-core` +2. Copy `braintrust-java-client-okhttp`'s [`OkHttpClient`](braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/OkHttpClient.kt) class into your code and customize it +3. Construct [`BraintrustClientImpl`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientImpl.kt) or [`BraintrustClientAsyncImpl`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientAsyncImpl.kt), similarly to [`BraintrustOkHttpClient`](braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClient.kt) or [`BraintrustOkHttpClientAsync`](braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClientAsync.kt), using your customized client + +### Completely custom HTTP client + +To use a completely custom HTTP client: + +1. Replace your [`braintrust-java` dependency](#installation) with `braintrust-java-core` +2. Write a class that implements the [`HttpClient`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/HttpClient.kt) interface +3. Construct [`BraintrustClientImpl`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientImpl.kt) or [`BraintrustClientAsyncImpl`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientAsyncImpl.kt), similarly to [`BraintrustOkHttpClient`](braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClient.kt) or [`BraintrustOkHttpClientAsync`](braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClientAsync.kt), using your new client class + ## Undocumented API functionality The SDK is typed for convenient usage of the documented API. However, it also supports working with undocumented or not yet supported parts of the API. From 15222f8192f329d22b029a5839d56899d2fc8690 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 23 Apr 2025 05:04:37 +0000 Subject: [PATCH 41/42] chore(ci): add timeout thresholds for CI jobs --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ebbaa260..9051fdd2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,7 @@ on: jobs: lint: + timeout-minutes: 10 name: lint runs-on: ubuntu-latest steps: @@ -30,6 +31,7 @@ jobs: - name: Run lints run: ./scripts/lint test: + timeout-minutes: 10 name: test runs-on: ubuntu-latest steps: From 3113bdad391e684600b6b9619fdd2b4d7450b8cd Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 23 Apr 2025 05:05:06 +0000 Subject: [PATCH 42/42] release: 0.9.0 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 83 +++++++++++++++++++++++++++++++++++ README.md | 10 ++--- build.gradle.kts | 2 +- 4 files changed, 90 insertions(+), 7 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 6538ca91..6d78745c 100755 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.8.0" + ".": "0.9.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 5898a8aa..9d47d1d9 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,88 @@ # Changelog +## 0.9.0 (2025-04-23) + +Full Changelog: [v0.8.0...v0.9.0](https://github.com/braintrustdata/braintrust-java/compare/v0.8.0...v0.9.0) + +### ⚠ BREAKING CHANGES + +* **client:** refactor exception structure and methods ([#164](https://github.com/braintrustdata/braintrust-java/issues/164)) +* **client:** **Migration:** Previously you would access error JSON on an exception via `exception.error()._additionalProperties()`, which would return `Map`. Now you would access this via `exception.body()`, which returns `JsonValue`. You should no longer assume that the returned error JSON is an object. You can check via `exception.body().asObject()`. + +### Features + +* **client:** add enum validation method ([7fe60b3](https://github.com/braintrustdata/braintrust-java/commit/7fe60b33c4097370f473c30564fccb8ce55e062a)) +* **client:** expose request body setter and getter ([#178](https://github.com/braintrustdata/braintrust-java/issues/178)) ([a36c0b6](https://github.com/braintrustdata/braintrust-java/commit/a36c0b633511abc41164b82429da85bd0810f732)) +* **client:** make datetime deserialization more lenient ([#177](https://github.com/braintrustdata/braintrust-java/issues/177)) ([a65987d](https://github.com/braintrustdata/braintrust-java/commit/a65987da85db749c526a110d7e624f38becf8fff)) +* **client:** make pagination robust to missing data ([445e30e](https://github.com/braintrustdata/braintrust-java/commit/445e30ebac1dd50e5cfc22aaf1ef9927fc13796f)) +* **client:** make union deserialization more robust ([#176](https://github.com/braintrustdata/braintrust-java/issues/176)) ([7fe60b3](https://github.com/braintrustdata/braintrust-java/commit/7fe60b33c4097370f473c30564fccb8ce55e062a)) +* **client:** support a lower jackson version ([#170](https://github.com/braintrustdata/braintrust-java/issues/170)) ([803e291](https://github.com/braintrustdata/braintrust-java/commit/803e2917444885e37e3148499f875ef59824f3c2)) +* **client:** support setting base URL via env var ([85b334a](https://github.com/braintrustdata/braintrust-java/commit/85b334ae4ce795835275970643f930468753d57a)) +* **client:** throw on incompatible jackson version ([803e291](https://github.com/braintrustdata/braintrust-java/commit/803e2917444885e37e3148499f875ef59824f3c2)) + + +### Bug Fixes + +* **client:** bump to better jackson version ([a2f69b5](https://github.com/braintrustdata/braintrust-java/commit/a2f69b5a6126c7c8ca17030bea1c0f660183f77f)) +* **client:** don't call `validate()` during deserialization if we don't have to ([#173](https://github.com/braintrustdata/braintrust-java/issues/173)) ([e71f053](https://github.com/braintrustdata/braintrust-java/commit/e71f0530ae5462de1089e41b3fefaaf18c140581)) +* **client:** limit json deserialization coercion ([#174](https://github.com/braintrustdata/braintrust-java/issues/174)) ([63e2b2c](https://github.com/braintrustdata/braintrust-java/commit/63e2b2ccb213bf215441d4c74dd4aa43f3697481)) +* **client:** map deserialization bug ([2a52b9f](https://github.com/braintrustdata/braintrust-java/commit/2a52b9fd35ea33391dad9f3e3098e5eb2afcca0d)) +* **client:** return `Optional<T>` instead of `Optional` ([#182](https://github.com/braintrustdata/braintrust-java/issues/182)) ([e3d5b19](https://github.com/braintrustdata/braintrust-java/commit/e3d5b190c14a9f398bfed2b8df461d01b411c1f3)) +* **client:** support kotlin 1.8 runtime ([#161](https://github.com/braintrustdata/braintrust-java/issues/161)) ([c9856ed](https://github.com/braintrustdata/braintrust-java/commit/c9856ed81fdfa4f17bdb96d66e45adc2751d4846)) +* pluralize `list` response variables ([#175](https://github.com/braintrustdata/braintrust-java/issues/175)) ([8d7b939](https://github.com/braintrustdata/braintrust-java/commit/8d7b939c590714e4344ea80d16b06414154cb691)) + + +### Performance Improvements + +* **client:** cached parsed type in `HttpResponseFor` ([#180](https://github.com/braintrustdata/braintrust-java/issues/180)) ([49c0c0a](https://github.com/braintrustdata/braintrust-java/commit/49c0c0af714e2770fe35456a046aff3a1d6759d8)) +* **internal:** improve compilation+test speed ([8efd75a](https://github.com/braintrustdata/braintrust-java/commit/8efd75a6d5b017099440e5dbb0b97d2b77d56c13)) + + +### Chores + +* **ci:** add timeout thresholds for CI jobs ([15222f8](https://github.com/braintrustdata/braintrust-java/commit/15222f8192f329d22b029a5839d56899d2fc8690)) +* **client:** refactor exception structure and methods ([#164](https://github.com/braintrustdata/braintrust-java/issues/164)) ([8463834](https://github.com/braintrustdata/braintrust-java/commit/8463834733a95f1afc905f3cfa74793b458e9a5a)) +* **client:** remove unnecessary json state from some query param classes ([7fe60b3](https://github.com/braintrustdata/braintrust-java/commit/7fe60b33c4097370f473c30564fccb8ce55e062a)) +* **internal:** add invalid json deserialization tests ([7fe60b3](https://github.com/braintrustdata/braintrust-java/commit/7fe60b33c4097370f473c30564fccb8ce55e062a)) +* **internal:** add json roundtripping tests ([7fe60b3](https://github.com/braintrustdata/braintrust-java/commit/7fe60b33c4097370f473c30564fccb8ce55e062a)) +* **internal:** codegen related update ([732dd76](https://github.com/braintrustdata/braintrust-java/commit/732dd768a9e4f048edf415d697e89c36551414d8)) +* **internal:** codegen related update ([#159](https://github.com/braintrustdata/braintrust-java/issues/159)) ([45cca50](https://github.com/braintrustdata/braintrust-java/commit/45cca506a7c0c1a165c0d4e54bf1950d4256d3a2)) +* **internal:** codegen related update ([#162](https://github.com/braintrustdata/braintrust-java/issues/162)) ([a490f5f](https://github.com/braintrustdata/braintrust-java/commit/a490f5fb5977d5347814c0d29a022468c8793e65)) +* **internal:** codegen related update ([#163](https://github.com/braintrustdata/braintrust-java/issues/163)) ([140986d](https://github.com/braintrustdata/braintrust-java/commit/140986d47b0e2f62d5ba3b84d459784e683fcda8)) +* **internal:** codegen related update ([#179](https://github.com/braintrustdata/braintrust-java/issues/179)) ([d32e7e5](https://github.com/braintrustdata/braintrust-java/commit/d32e7e5d3343041c4404178e0ebf48efd02ddc22)) +* **internal:** delete unused methods and annotations ([#171](https://github.com/braintrustdata/braintrust-java/issues/171)) ([2a52b9f](https://github.com/braintrustdata/braintrust-java/commit/2a52b9fd35ea33391dad9f3e3098e5eb2afcca0d)) +* **internal:** expand CI branch coverage ([6e596e4](https://github.com/braintrustdata/braintrust-java/commit/6e596e46185da32341ce8d186a96336f26b2cd56)) +* **internal:** fix example formatting ([#166](https://github.com/braintrustdata/braintrust-java/issues/166)) ([3ce1a02](https://github.com/braintrustdata/braintrust-java/commit/3ce1a023b3013ffeb9fa9651b42ef3ba5a11fc6e)) +* **internal:** generate more tests ([e7cdefc](https://github.com/braintrustdata/braintrust-java/commit/e7cdefcd06a55332f6e7ef6a6b729f33207a7834)) +* **internal:** make multipart assertions more robust ([6d40318](https://github.com/braintrustdata/braintrust-java/commit/6d403189bb05ab3934586907f2cb8f093e65c805)) +* **internal:** reduce CI branch coverage ([491a2ae](https://github.com/braintrustdata/braintrust-java/commit/491a2aeecc8b972efec17ec3e62e2848d1020158)) +* **internal:** reformat some tests ([#160](https://github.com/braintrustdata/braintrust-java/issues/160)) ([e7cdefc](https://github.com/braintrustdata/braintrust-java/commit/e7cdefcd06a55332f6e7ef6a6b729f33207a7834)) +* **internal:** remove unnecessary `assertNotNull` calls ([6d40318](https://github.com/braintrustdata/braintrust-java/commit/6d403189bb05ab3934586907f2cb8f093e65c805)) +* **internal:** remove unnecessary import ([#167](https://github.com/braintrustdata/braintrust-java/issues/167)) ([03d8ca9](https://github.com/braintrustdata/braintrust-java/commit/03d8ca931ab7599f98cef22d0b43a39b0d002f65)) +* **internal:** swap from `Builder().from(...)` to `toBuilder()` ([#172](https://github.com/braintrustdata/braintrust-java/issues/172)) ([d15ef50](https://github.com/braintrustdata/braintrust-java/commit/d15ef50ea2a826653c7b2ddebabefadc60b1864d)) +* **internal:** swap from `getNullable` to `getOptional` ([#181](https://github.com/braintrustdata/braintrust-java/issues/181)) ([2fca092](https://github.com/braintrustdata/braintrust-java/commit/2fca092faa8a4679ff792bfd746f9638a7187ba3)) +* **internal:** version bump ([#157](https://github.com/braintrustdata/braintrust-java/issues/157)) ([0492bdd](https://github.com/braintrustdata/braintrust-java/commit/0492bddf28ecfea9a5c901e78ff07918a265f6f6)) + + +### Documentation + +* add comments for page methods ([445e30e](https://github.com/braintrustdata/braintrust-java/commit/445e30ebac1dd50e5cfc22aaf1ef9927fc13796f)) +* add comments to `JsonField` classes ([e3d5b19](https://github.com/braintrustdata/braintrust-java/commit/e3d5b190c14a9f398bfed2b8df461d01b411c1f3)) +* **client:** update jackson compat error message ([6039ca5](https://github.com/braintrustdata/braintrust-java/commit/6039ca545cba51e71e02f4db3b26a0964f3bd522)) +* document how to forcibly omit required field ([e797de1](https://github.com/braintrustdata/braintrust-java/commit/e797de1a9185adb1dab8f9670fd2d8e4b03e2142)) +* explain http client customization ([1388be4](https://github.com/braintrustdata/braintrust-java/commit/1388be42ac426c5d1b934712302c6acecf20c885)) +* explain jackson compat in readme ([8fd288d](https://github.com/braintrustdata/braintrust-java/commit/8fd288d5ef4d5053f20b7db81bde980a465d996b)) +* minor readme tweak ([#169](https://github.com/braintrustdata/braintrust-java/issues/169)) ([4154acd](https://github.com/braintrustdata/braintrust-java/commit/4154acdf5be17f6b8c3ec26ccf5ca25b61c75404)) +* refine comments on multipart params ([#165](https://github.com/braintrustdata/braintrust-java/issues/165)) ([6d40318](https://github.com/braintrustdata/braintrust-java/commit/6d403189bb05ab3934586907f2cb8f093e65c805)) +* swap examples used in readme ([#183](https://github.com/braintrustdata/braintrust-java/issues/183)) ([e797de1](https://github.com/braintrustdata/braintrust-java/commit/e797de1a9185adb1dab8f9670fd2d8e4b03e2142)) +* update readme exception docs ([#168](https://github.com/braintrustdata/braintrust-java/issues/168)) ([39e01a6](https://github.com/braintrustdata/braintrust-java/commit/39e01a6fb2b29e1c8806ec27191cfef234b012d9)) + + +### Refactors + +* **client:** deduplicate page response classes ([445e30e](https://github.com/braintrustdata/braintrust-java/commit/445e30ebac1dd50e5cfc22aaf1ef9927fc13796f)) +* **client:** migrate pages to builder pattern ([b61888c](https://github.com/braintrustdata/braintrust-java/commit/b61888c0b3080b0ed42f8179a9fc772333cb0d9c)) + ## 0.8.0 (2025-03-18) Full Changelog: [v0.7.0...v0.8.0](https://github.com/braintrustdata/braintrust-java/compare/v0.7.0...v0.8.0) diff --git a/README.md b/README.md index 4eac9576..18106805 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ -[![Maven Central](https://img.shields.io/maven-central/v/com.braintrustdata.api/braintrust-java)](https://central.sonatype.com/artifact/com.braintrustdata.api/braintrust-java/0.8.0) -[![javadoc](https://javadoc.io/badge2/com.braintrustdata.api/braintrust-java/0.8.0/javadoc.svg)](https://javadoc.io/doc/com.braintrustdata.api/braintrust-java/0.8.0) +[![Maven Central](https://img.shields.io/maven-central/v/com.braintrustdata.api/braintrust-java)](https://central.sonatype.com/artifact/com.braintrustdata.api/braintrust-java/0.9.0) +[![javadoc](https://javadoc.io/badge2/com.braintrustdata.api/braintrust-java/0.9.0/javadoc.svg)](https://javadoc.io/doc/com.braintrustdata.api/braintrust-java/0.9.0) @@ -15,7 +15,7 @@ It is generated with [Stainless](https://www.stainless.com/). -The REST API documentation can be found on [www.braintrustdata.com](https://www.braintrustdata.com/docs/api/spec). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.braintrustdata.api/braintrust-java/0.8.0). +The REST API documentation can be found on [www.braintrustdata.com](https://www.braintrustdata.com/docs/api/spec). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.braintrustdata.api/braintrust-java/0.9.0). @@ -26,7 +26,7 @@ The REST API documentation can be found on [www.braintrustdata.com](https://www. ### Gradle ```kotlin -implementation("com.braintrustdata.api:braintrust-java:0.8.0") +implementation("com.braintrustdata.api:braintrust-java:0.9.0") ``` ### Maven @@ -35,7 +35,7 @@ implementation("com.braintrustdata.api:braintrust-java:0.8.0") com.braintrustdata.api braintrust-java - 0.8.0 + 0.9.0 ``` diff --git a/build.gradle.kts b/build.gradle.kts index 3a613beb..d8afa3b2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ repositories { allprojects { group = "com.braintrustdata.api" - version = "0.8.0" // x-release-please-version + version = "0.9.0" // x-release-please-version } subprojects {