From 55e6f3c37716cf6de9c2d6e58089128d5402df80 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:06 +0000 Subject: [PATCH] feat(client): support a lower jackson version 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 7a2f0205..1120ada5 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.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 @@ -195,529 +194,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 @@ -726,321 +513,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) @@ -1201,17 +1220,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 @@ -1226,20 +1245,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) @@ -1314,7 +1328,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) : @@ -1432,20 +1457,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 @@ -1474,21 +1498,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) @@ -1587,10 +1605,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 @@ -1727,30 +1757,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 @@ -1837,32 +1880,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) @@ -2029,10 +2055,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 { @@ -2152,23 +2193,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 @@ -2217,22 +2262,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) @@ -2345,25 +2383,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 @@ -2398,21 +2451,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) @@ -2513,10 +2560,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 { @@ -2882,20 +2941,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 @@ -2924,21 +2982,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) @@ -3031,10 +3083,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 { @@ -3152,35 +3216,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) @@ -3233,7 +3294,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 { @@ -3369,23 +3440,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 * @@ -3434,22 +3509,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) @@ -3571,10 +3639,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 b4701359..ddb8d36b 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.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 @@ -195,529 +194,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 @@ -726,321 +513,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) @@ -1201,17 +1220,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 @@ -1226,20 +1245,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) @@ -1314,7 +1328,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) : @@ -1432,20 +1457,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 @@ -1474,21 +1498,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) @@ -1587,10 +1605,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 @@ -1727,30 +1757,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 @@ -1837,32 +1880,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) @@ -2029,10 +2055,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 { @@ -2152,23 +2193,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 @@ -2217,22 +2262,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) @@ -2345,25 +2383,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 @@ -2398,21 +2451,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) @@ -2513,10 +2560,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 { @@ -2882,20 +2941,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 @@ -2924,21 +2982,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) @@ -3031,10 +3083,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 { @@ -3152,35 +3216,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) @@ -3233,7 +3294,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 { @@ -3369,23 +3440,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 * @@ -3434,22 +3509,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) @@ -3571,10 +3639,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 91c3bd36..f9a06721 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.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 @@ -129,190 +128,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) = @@ -430,291 +686,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) @@ -875,17 +881,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 @@ -900,20 +906,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) @@ -988,7 +989,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) : @@ -1106,20 +1118,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 @@ -1148,21 +1159,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) @@ -1261,10 +1266,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 @@ -1401,30 +1418,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 @@ -1511,32 +1541,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) @@ -1703,10 +1716,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 { @@ -1826,23 +1854,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 @@ -1891,22 +1923,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) @@ -2019,25 +2044,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 @@ -2072,21 +2112,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) @@ -2187,10 +2221,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 { @@ -2556,20 +2602,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 @@ -2598,21 +2643,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) @@ -2705,10 +2744,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()